summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/cobra/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/cobra/README.md')
-rw-r--r--vendor/github.com/spf13/cobra/README.md30
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/github.com/spf13/cobra/README.md b/vendor/github.com/spf13/cobra/README.md
index e249c1bcb..a38137b25 100644
--- a/vendor/github.com/spf13/cobra/README.md
+++ b/vendor/github.com/spf13/cobra/README.md
@@ -485,6 +485,36 @@ when the `--author` flag is not provided by user.
More in [viper documentation](https://github.com/spf13/viper#working-with-flags).
+## Positional and Custom Arguments
+
+Validation of positional arguments can be specified using the `Args` field.
+
+The follow validators are built in:
+
+- `NoArgs` - the command will report an error if there are any positional args.
+- `ArbitraryArgs` - the command will accept any args.
+- `OnlyValidArgs` - the command will report an error if there are any positional args that are not in the ValidArgs list.
+- `MinimumNArgs(int)` - the command will report an error if there are not at least N positional args.
+- `MaximumNArgs(int)` - the command will report an error if there are more than N positional args.
+- `ExactArgs(int)` - the command will report an error if there are not exactly N positional args.
+- `RangeArgs(min, max)` - the command will report an error if the number of args is not between the minimum and maximum number of expected args.
+
+A custom validator can be provided like this:
+
+```go
+
+Args: func validColorArgs(cmd *cobra.Command, args []string) error {
+ if err := cli.RequiresMinArgs(1)(cmd, args); err != nil {
+ return err
+ }
+ if myapp.IsValidColor(args[0]) {
+ return nil
+ }
+ return fmt.Errorf("Invalid color specified: %s", args[0])
+}
+
+```
+
## Example
In the example below, we have defined three commands. Two are at the top level