@@ -32,17 +32,40 @@ type PostRunMap map[PostRunType]func(Response, ResponseEmitter) error
32
32
// Command is a runnable command, with input arguments and options (flags).
33
33
// It can also have Subcommands, to group units of work into sets.
34
34
type Command struct {
35
- Options []Option
35
+ // Options defines the flags accepted by the command. Flags on specified
36
+ // on parent commands are inherited by sub commands.
37
+ Options []Option
38
+
39
+ // Arguments defines the positional arguments for the command. These
40
+ // arguments can be strings and/or files.
41
+ //
42
+ // The rules for valid arguments are as follows:
43
+ //
44
+ // 1. No required arguments may follow optional arguments.
45
+ // 2. There can be at most one STDIN argument.
46
+ // 3. There can be at most one variadic argument, and it must be last.
36
47
Arguments []Argument
37
- PreRun func (req * Request , env Environment ) error
48
+
49
+ // PreRun is run before Run. When executing a command on a remote
50
+ // daemon, PreRun is always run in the local process.
51
+ PreRun func (req * Request , env Environment ) error
38
52
39
53
// Run is the function that processes the request to generate a response.
40
54
// Note that when executing the command over the HTTP API you can only read
41
55
// after writing when using multipart requests. The request body will not be
42
56
// available for reading after the HTTP connection has been written to.
43
- Run Function
44
- PostRun PostRunMap
57
+ Run Function
58
+
59
+ // PostRun is run after Run, and can transform results returned by run.
60
+ // When executing a command on a remote daemon, PostRun is always run in
61
+ // the local process.
62
+ PostRun PostRunMap
63
+
64
+ // Encoders encode results from Run (and/or PostRun) in the desired
65
+ // encoding.
45
66
Encoders EncoderMap
67
+
68
+ // Helptext is the command's help text.
46
69
Helptext HelpText
47
70
48
71
// External denotes that a command is actually an external binary.
@@ -54,7 +77,17 @@ type Command struct {
54
77
// the Run Function.
55
78
//
56
79
// ie. If command Run returns &Block{}, then Command.Type == &Block{}
57
- Type interface {}
80
+ Type interface {}
81
+
82
+ // Subcommands allow attaching sub commands to a command.
83
+ //
84
+ // Note: A command can specify both a Run function and Subcommands. If
85
+ // invoked with no arguments, or an argument that matches no
86
+ // sub commands, the Run function of the current command will be invoked.
87
+ //
88
+ // Take care when specifying both a Run function and Subcommands. A
89
+ // simple typo in a sub command will invoke the parent command and may
90
+ // end up returning a cryptic error to the user.
58
91
Subcommands map [string ]* Command
59
92
}
60
93
0 commit comments