commands: Added HelpText struct to organize different help text fields in Commands
Matt Bell committed
Nov 12, 2014 at 01:24 UTC
475f3f485b79d28a4863e152f022cce856feaa1f
1 file changed
+17
-2
commands/command.go
+17
-2
@@ -19,6 +19,21 @@ type Function func(Request) (interface{}, error)
19
// (or an error on failure)
20
type Marshaller func(Response) ([]byte, error)
21
22
+// HelpText is a set of strings used to generate command help text. The help
23
+// text follows formats similar to man pages, but not exactly the same.
24
+type HelpText struct {
25
+ // required
26
+ Tagline string // used in <cmd usage>
27
+ ShortDescription string // used in DESCRIPTION
28
+
29
+ // optional - whole section overrides
30
+ Usage string // overrides USAGE section
31
+ LongDescription string // overrides DESCRIPTION section
32
+ Options string // overrides OPTIONS section
33
+ Arguments string // overrides ARGUMENTS section
34
+ Subcommands string // overrides SUBCOMMANDS section
35
+}
36
+
37
// TODO: check Argument definitions when creating a Command
38
// (might need to use a Command constructor)
39
// * make sure any variadic args are at the end
@@ -28,8 +43,7 @@ type Marshaller func(Response) ([]byte, error)
43
// Command is a runnable command, with input arguments and options (flags).
44
// It can also have Subcommands, to group units of work into sets.
45
type Command struct {
31
- // MAYBE_TODO: move all the text fields into a struct
32
- // MAYBE_TODO: move these out of command and put them somewhere in commands/cli
46
+ // TODO: remove these fields after porting commands to HelpText struct
47
Description string
48
Help string
49
SubcommandHelp string
@@ -40,6 +54,7 @@ type Command struct {
54
Arguments []Argument
55
Run Function
56
Marshallers map[EncodingType]Marshaller
57
+ Helptext HelpText
58
59
// Type describes the type of the output of the Command's Run Function.
60
// In precise terms, the value of Type is an instance of the return type of