@cryptotaxi247 / kubo / commits / f22ac196b

commands: Added Recursive modifier to Argument

Matt Bell committed Nov 16, 2014 at 19:12 UTC f22ac196bb9227f8845e0a884b59b7d841b99534
1 file changed +17 -3
commands/argument.go
+17 -3
@@ -10,9 +10,10 @@ const (
10 type Argument struct {
11 Name string
12 Type ArgumentType
13 - Required bool
14 - Variadic bool
15 - SupportsStdin bool
13 + Required bool // error if no value is specified
14 + Variadic bool // unlimited values can be specfied
15 + SupportsStdin bool // can accept stdin as a value
16 + Recursive bool // supports recursive file adding (with '-r' flag)
17 Description string
18 }
19
@@ -36,7 +37,20 @@ func FileArg(name string, required, variadic bool, description string) Argument
37 }
38 }
39
40 +// TODO: modifiers might need a different API?
41 +// e.g. passing enum values into arg constructors variadically
42 +// (`FileArg("file", ArgRequired, ArgStdin, ArgRecursive)`)
43 +
44 func (a Argument) EnableStdin() Argument {
45 a.SupportsStdin = true
46 return a
47 }
48 +
49 +func (a Argument) EnableRecursive() Argument {
50 + if a.Type != ArgFile {
51 + panic("Only ArgFile arguments can enable recursive")
52 + }
53 +
54 + a.Recursive = true
55 + return a
56 +}