Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: document command fields #192

Merged
merged 1 commit into from
Apr 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,40 @@ type PostRunMap map[PostRunType]func(Response, ResponseEmitter) error
// Command is a runnable command, with input arguments and options (flags).
// It can also have Subcommands, to group units of work into sets.
type Command struct {
Options []Option
// Options defines the flags accepted by the command. Flags on specified
// on parent commands are inherited by sub commands.
Options []Option

// Arguments defines the positional arguments for the command. These
// arguments can be strings and/or files.
//
// The rules for valid arguments are as follows:
//
// 1. No required arguments may follow optional arguments.
// 2. There can be at most one STDIN argument.
// 3. There can be at most one variadic argument, and it must be last.
Arguments []Argument
PreRun func(req *Request, env Environment) error

// PreRun is run before Run. When executing a command on a remote
// daemon, PreRun is always run in the local process.
PreRun func(req *Request, env Environment) error

// Run is the function that processes the request to generate a response.
// Note that when executing the command over the HTTP API you can only read
// after writing when using multipart requests. The request body will not be
// available for reading after the HTTP connection has been written to.
Run Function
PostRun PostRunMap
Run Function

// PostRun is run after Run, and can transform results returned by run.
// When executing a command on a remote daemon, PostRun is always run in
// the local process.
PostRun PostRunMap

// Encoders encode results from Run (and/or PostRun) in the desired
// encoding.
Encoders EncoderMap

// Helptext is the command's help text.
Helptext HelpText

// External denotes that a command is actually an external binary.
Expand All @@ -54,7 +77,17 @@ type Command struct {
// the Run Function.
//
// ie. If command Run returns &Block{}, then Command.Type == &Block{}
Type interface{}
Type interface{}

// Subcommands allow attaching sub commands to a command.
//
// Note: A command can specify both a Run function and Subcommands. If
// invoked with no arguments, or an argument that matches no
// sub commands, the Run function of the current command will be invoked.
//
// Take care when specifying both a Run function and Subcommands. A
// simple typo in a sub command will invoke the parent command and may
// end up returning a cryptic error to the user.
Subcommands map[string]*Command
}

Expand Down