mirror of
https://github.com/spf13/cobra
synced 2025-05-06 05:17:21 +00:00
Add usage example for required flags
This commit is contained in:
parent
3a7eb146ba
commit
ee504cbef1
1 changed files with 11 additions and 2 deletions
|
@ -366,6 +366,15 @@ when the `--author` flag is not provided by user.
|
||||||
|
|
||||||
More in [viper documentation](https://github.com/spf13/viper#working-with-flags).
|
More in [viper documentation](https://github.com/spf13/viper#working-with-flags).
|
||||||
|
|
||||||
|
### Required flags
|
||||||
|
|
||||||
|
Flags are optional by default. If instead you wish your command to report an error
|
||||||
|
when a flag has not been set, mark it as required:
|
||||||
|
```go
|
||||||
|
rootCmd.Flags().StringVarP(&Region, "region", "r", "", "AWS region (required)")
|
||||||
|
rootCmd.MarkFlagRequired("region")
|
||||||
|
```
|
||||||
|
|
||||||
## Positional and Custom Arguments
|
## Positional and Custom Arguments
|
||||||
|
|
||||||
Validation of positional arguments can be specified using the `Args` field
|
Validation of positional arguments can be specified using the `Args` field
|
||||||
|
|
Loading…
Add table
Reference in a new issue