Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SkipFile = errors.New("skip this file")
SkipFile is returned by the walker function to indicate a file should not be returned during the workspace scan
Functions ¶
func ContextValue ¶
ContextValue provides an action that sets the given value into the context. The only supported type is *Workspace.
func SetWorkingDir ¶
SetWorkingDir sets the current directory. It is typical within apps that work with workspaces to allow the user to set the current directory. \
func SetupWorkspace ¶
SetupWorkspace provides the action that sets up the workspace, which locks in the workspace directories.
Types ¶
type Workspace ¶
type Workspace struct {
// Action provides the action to provide when the workspace is
// added to a pipeline.
cli.Action
// contains filtered or unexported fields
}
Workspace provides the root directory of a project-specific workspace. The workspace provides two capabilities:
- The workspace finder locates the root directory of a project. By default, the workspace is found by searching up the directory hierarchy until it finds a directory which contains a configuration sentinel, typically a directory which the same name as the app with a leading period. For example, this is what Git does when it finds the .git directory.
- The workspace can load files. These files could be application files or configuration files.
func NewWorkspace ¶
func NewWorkspace(opts ...WorkspaceOption) *Workspace
NewWorkspace creates a workspace with the default action, which registers the flags and adds the workspace to the context.
func WorkspaceFromContext ¶
WorkspaceFromContext gets the Workspace from the context otherwise panics
func (*Workspace) Apply ¶
func (w *Workspace) Apply(opts ...WorkspaceOption)
Apply applies options to the workspace
func (*Workspace) ConfigDir ¶
ConfigDir gets the directory where configuration is stored. Typically, this has the same name as the app with a leading dot, e.g. $WORKSPACE_DIR/.app.
func (*Workspace) Dir ¶
Dir gets the workspace directory, which is the root of all content in the workspace. The directory is set to the current working directory at the time the app starts, sometime in the Before pipeline.
func (*Workspace) Files ¶
Files enumerates all files in the workspace which match the filters. The result contains the name of the file and a io/fs.DirEntry.
func (*Workspace) LoadFiles ¶
LoadFiles loads all files in the workspace which match the filters. This method is good for a single pass, not dynamic workspaces where files are expected to change while the app is running. The type of the items returned from this depend upon what was set as the loader. When no loader is set, the result will be fs.File.
type WorkspaceFileLoaderFunc ¶
WorkspaceFileLoaderFunc defines the function for loading files in a workspace.
type WorkspaceFinder ¶
type WorkspaceFinder interface {
// FindWorkspacePath locates the workspace. Param cwd represents the
// the current working directory
FindWorkspacePath(c context.Context, f fs.FS, cwd string) (string, error)
}
WorkspaceFinder locates the workspace
var DefaultWorkspaceFinder WorkspaceFinder = new(defaultWorkspaceFinder)
DefaultWorkspaceFinder provides the default logic for finding a workspace
type WorkspaceOption ¶
WorkspaceOption provides an option for setting up the Workspace. This is also a cli.Action, which means it can be used within pipelines. Typically, when used within the Action pipeline, it sets the option on the workspace. When used within the Uses pipeline, it may also configure a flag or other behavior.
func WithConfigDir ¶
func WithConfigDir(diropt ...string) WorkspaceOption
WithConfigDir sets the workspace config directory. This can be used as an option to NewWorkspace or Workspace.Apply, but when it is, the diropt must be specified. It can also be used as an Action. When it is used within the Uses pipeline, it initializes reasonable defaults for a flag and will set the directory within the workspace in the Before timing. The flag will either use the directory specified by diropt or its own value if diropt is not specified.
func WithFS ¶
func WithFS(f fs.FS) WorkspaceOption
WithFS specifies the file system to use for the workspace. By default, the workspace with use os.DirFS corresponding to the workspace directory.
func WithFileLoader ¶
func WithFileLoader(loader WorkspaceFileLoaderFunc) WorkspaceOption
WithFileLoader is an option that determines how to read files in a workspace.
func WithFinder ¶
func WithFinder(finder WorkspaceFinder) WorkspaceOption
WithFinder is an option that determines how to finder the workspace
func WithWalkDirFunc ¶
func WithWalkDirFunc(fn fs.WalkDirFunc) WorkspaceOption
WithWalkDirFunc specifies the function that walks the directory for files. The function is used in a call to io/fs.WalkDir, where it can return io/fs.SkipDir and io/fs.SkipAll, with the same behavior. It can also return SkipFile introduced by this package to indicate that a file is skipped in the result of the Workspace.Files and Workspace.LoadFiles methods.