-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from ipfs/merge/cmdkit
merge in go-ipfs-cmdkit
- Loading branch information
Showing
35 changed files
with
692 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ env: | |
global: | ||
- GOTFLAGS="-race" | ||
matrix: | ||
- BUILD_DEPTYPE=gx | ||
- BUILD_DEPTYPE=gomod | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cmds | ||
|
||
type ArgumentType int | ||
|
||
const ( | ||
ArgString ArgumentType = iota | ||
ArgFile | ||
) | ||
|
||
type Argument struct { | ||
Name string | ||
Type ArgumentType | ||
Required bool // error if no value is specified | ||
Variadic bool // unlimited values can be specfied | ||
SupportsStdin bool // can accept stdin as a value | ||
Recursive bool // supports recursive file adding (with '-r' flag) | ||
Description string | ||
} | ||
|
||
func StringArg(name string, required, variadic bool, description string) Argument { | ||
return Argument{ | ||
Name: name, | ||
Type: ArgString, | ||
Required: required, | ||
Variadic: variadic, | ||
Description: description, | ||
} | ||
} | ||
|
||
func FileArg(name string, required, variadic bool, description string) Argument { | ||
return Argument{ | ||
Name: name, | ||
Type: ArgFile, | ||
Required: required, | ||
Variadic: variadic, | ||
Description: description, | ||
} | ||
} | ||
|
||
// TODO: modifiers might need a different API? | ||
// e.g. passing enum values into arg constructors variadically | ||
// (`FileArg("file", ArgRequired, ArgStdin, ArgRecursive)`) | ||
|
||
func (a Argument) EnableStdin() Argument { | ||
a.SupportsStdin = true | ||
return a | ||
} | ||
|
||
func (a Argument) EnableRecursive() Argument { | ||
if a.Type != ArgFile { | ||
panic("Only FileArgs can enable recursive") | ||
} | ||
|
||
a.Recursive = true | ||
return a | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.