workspace

package
v3.0.11+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMissingMetadata

func IsMissingMetadata(err error) bool

IsMissingMetadata verifies the type of error.

func IsNotExist

func IsNotExist(err error) bool

IsNotExist checks if this is an ErrNotExist error.

func IsNotInWorkspace

func IsNotInWorkspace(err error) bool

IsNotInWorkspace checks if this is an ErrNotInWorkspace error.

Types

type Document

type Document struct {
	Root         string
	RelativePath string
}

Document is a file in a directory.

func NewDocument

func NewDocument(root, path string) (Document, error)

NewDocument creates a document from the filepath. The root is typically the root of the exercise, and path is the absolute path to the file.

func (Document) Filepath

func (doc Document) Filepath() string

Filepath is the absolute path to the document on the filesystem.

func (Document) Path

func (doc Document) Path() string

Path is the normalized path. It uses forward slashes regardless of the operating system.

type ErrNotExist

type ErrNotExist string

ErrNotExist signals that the target directory could not be located.

func (ErrNotExist) Error

func (err ErrNotExist) Error() string

type ErrNotInWorkspace

type ErrNotInWorkspace string

ErrNotInWorkspace signals that the target directory is outside the configured workspace.

func (ErrNotInWorkspace) Error

func (err ErrNotInWorkspace) Error() string

type Exercise

type Exercise struct {
	Root      string
	Track     string
	Slug      string
	Documents []Document
}

Exercise is an implementation of a problem in a track.

func NewExerciseFromDir

func NewExerciseFromDir(dir string) Exercise

NewExerciseFromDir constructs an exercise given the exercise directory.

func (Exercise) Filepath

func (e Exercise) Filepath() string

Filepath is the absolute path on the filesystem.

func (Exercise) HasLegacyMetadata

func (e Exercise) HasLegacyMetadata() (bool, error)

HasLegacyMetadata checks for the presence of a legacy exercise metadata file. If there is no such file, it could also be an unrelated directory.

func (Exercise) HasMetadata

func (e Exercise) HasMetadata() (bool, error)

HasMetadata checks for the presence of an exercise metadata file. If there is no such file, this may be a legacy exercise. It could also be an unrelated directory.

func (Exercise) LegacyMetadataFilepath

func (e Exercise) LegacyMetadataFilepath() string

LegacyMetadataFilepath is the absolute path to the legacy exercise metadata.

func (Exercise) MetadataDir

func (e Exercise) MetadataDir() string

MetadataDir returns the directory that the exercise metadata lives in. For now this is the exercise directory.

func (Exercise) MetadataFilepath

func (e Exercise) MetadataFilepath() string

MetadataFilepath is the absolute path to the exercise metadata.

func (Exercise) MigrateLegacyMetadataFile

func (e Exercise) MigrateLegacyMetadataFile() (MigrationStatus, error)

MigrateLegacyMetadataFile migrates a legacy metadata file to the modern location. This is a noop if the metadata file isn't legacy. If both legacy and modern metadata files exist, the legacy file will be deleted.

func (Exercise) Path

func (e Exercise) Path() string

Path is the normalized relative path. It always has forward slashes, regardless of the operating system.

type ExerciseMetadata

type ExerciseMetadata struct {
	Track       string     `json:"track"`
	Exercise    string     `json:"exercise"`
	ID          string     `json:"id"`
	Team        string     `json:"team,omitempty"`
	URL         string     `json:"url"`
	Handle      string     `json:"handle"`
	IsRequester bool       `json:"is_requester"`
	SubmittedAt *time.Time `json:"submitted_at,omitempty"`
	Dir         string     `json:"-"`
	AutoApprove bool       `json:"auto_approve"`
}

ExerciseMetadata contains metadata about a user's exercise.

func NewExerciseMetadata

func NewExerciseMetadata(dir string) (*ExerciseMetadata, error)

NewExerciseMetadata reads exercise metadata from a file in the given directory.

func (*ExerciseMetadata) PathToParent

func (em *ExerciseMetadata) PathToParent() string

PathToParent is the relative path from the workspace to the parent dir.

func (*ExerciseMetadata) String

func (em *ExerciseMetadata) String() string

func (*ExerciseMetadata) Suffix

func (em *ExerciseMetadata) Suffix() string

Suffix is the serial numeric value appended to an exercise directory. This is appended to avoid name conflicts, and does not indicate a particular iteration.

func (*ExerciseMetadata) Write

func (em *ExerciseMetadata) Write(dir string) error

Write stores exercise metadata to a file.

type MigrationStatus

type MigrationStatus int

MigrationStatus represents the result of migrating a legacy metadata file.

const (
	MigrationStatusNoop MigrationStatus = iota
	MigrationStatusMigrated
	MigrationStatusRemoved
)

MigrationStatus

func (MigrationStatus) String

func (m MigrationStatus) String() string

type PathType

type PathType int

PathType is either a path to a dir or file, or the name of an exercise.

const (
	// TypeExerciseID is the name of an exercise.
	TypeExerciseID PathType = iota
	// TypeDir is a relative or absolute path to a directory.
	TypeDir
	// TypeFile is a relative or absolute path to a file.
	TypeFile
)

func DetectPathType

func DetectPathType(path string) (PathType, error)

DetectPathType determines whether the given path is a directory, a file, or the name of an exercise.

type Workspace

type Workspace struct {
	Dir string
}

Workspace represents a user's Exercism workspace. It may contain a user's own exercises, and other people's exercises that they've downloaded to look at or run locally.

func New

func New(dir string) (Workspace, error)

New returns a configured workspace.

func (Workspace) ExerciseDir

func (ws Workspace) ExerciseDir(s string) (string, error)

ExerciseDir determines the root directory of an exercise. This is the directory that contains the exercise metadata file.

func (Workspace) Exercises

func (ws Workspace) Exercises() ([]Exercise, error)

Exercises returns the user's exercises within the workspace. This doesn't find legacy exercises where the metadata is missing.

func (Workspace) PotentialExercises

func (ws Workspace) PotentialExercises() ([]Exercise, error)

PotentialExercises are a first-level guess at the user's exercises. It looks at the workspace structurally, and guesses based on the location of the directory. E.g. any top level directory within the workspace (except 'users') is assumed to be a track, and any directory within there again is assumed to be an exercise.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL