workspace

package
v3.0.0-alpha.3+incompa... Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

func IsSolutionPath

func IsSolutionPath(solutionID, path string) (bool, error)

IsSolutionPath checks whether the given path contains the solution with the given ID.

Types

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 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 Solution

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

Solution contains metadata about a user's solution.

func NewSolution

func NewSolution(dir string) (*Solution, error)

NewSolution reads solution metadata from a file in the given directory.

func (*Solution) String

func (s *Solution) String() string

func (*Solution) Suffix

func (s *Solution) 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 (*Solution) Write

func (s *Solution) Write(dir string) error

Write stores solution metadata to a file.

type Solutions

type Solutions []*Solution

Solutions is a collection of solutions to interactively choose from.

func NewSolutions

func NewSolutions(paths []string) (Solutions, error)

NewSolutions loads up the solution metadata for each of the provided paths.

func (Solutions) Display

func (sx Solutions) Display() string

Display shows a numbered list of the solutions to choose from. The list starts at 1, since that seems better in a user interface.

func (Solutions) Get

func (sx Solutions) Get(n int) (*Solution, error)

Get returns the solution corresponding to the number. The list starts at 1, since that seems better in a user interface.

func (Solutions) Pick

func (sx Solutions) Pick(prompt string) (*Solution, error)

Pick lets a user interactively select a solution from a list.

func (Solutions) ReadSelection

func (sx Solutions) ReadSelection(r io.Reader) (int, error)

ReadSelection reads the user's selection and converts it to a number.

type Transmission

type Transmission struct {
	Files []string
	Dir   string
	// contains filtered or unexported fields
}

Transmission as the data necessary to submit a solution.

func NewTransmission

func NewTransmission(root string, args []string) (*Transmission, error)

NewTransmission processes the arguments to the submit command to prep a submission.

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

New returns a configured workspace.

func (Workspace) Locate

func (ws Workspace) Locate(exercise string) ([]string, error)

Locate the matching directories within the workspace. This will look for an exact match on absolute or relative paths. If given the base name of a directory with no path information it It will look for all directories with that name, or that are named with a numerical suffix.

func (Workspace) ResolveSolutionPath

func (ws Workspace) ResolveSolutionPath(paths []string, exercise, solutionID string, existsFn func(string, string) (bool, error)) (string, error)

ResolveSolutionPath determines the path for the given exercise solution. It will locate an existing path, or indicate the name of a new path, if this is a new solution.

func (Workspace) SolutionDir

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

SolutionDir determines the root directory of a solution. This is the directory that contains the solution metadata file.

func (Workspace) SolutionPath

func (ws Workspace) SolutionPath(exercise, solutionID string) (string, error)

SolutionPath returns the full path where the exercise will be stored. By default this the directory name matches that of the exercise, but if a different solution already exists, then a numeric suffix will be added to the name.

Jump to

Keyboard shortcuts

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