config

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func ContextValue(v contextValue) cli.Action

ContextValue provides an action that sets the given value into the context. The only supported type is *Workspace.

func SetWorkingDir

func SetWorkingDir(diropt ...string) cli.Action

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

func SetupWorkspace() cli.Action

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:

  1. 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.
  2. 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

func WorkspaceFromContext(ctx context.Context) *Workspace

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

func (w *Workspace) ConfigDir() string

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

func (w *Workspace) Dir() string

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) FS

func (w *Workspace) FS() fs.FS

FS gets the file system that represents the workspace.

func (*Workspace) Files

func (w *Workspace) Files(diropt ...string) iter.Seq2[string, fs.DirEntry]

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

func (w *Workspace) LoadFiles(diropt ...string) iter.Seq[any]

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

type WorkspaceFileLoaderFunc func(root fs.FS, name string, d fs.DirEntry) (any, error)

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

type WorkspaceOption interface {
	cli.Action
	// contains filtered or unexported methods
}

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.

Jump to

Keyboard shortcuts

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