mirror of
https://github.com/spf13/cobra
synced 2024-12-27 14:57:06 +00:00
Add example for making persistent flags required (#1135)
This commit is contained in:
parent
723d0c36fc
commit
142dfb15a8
1 changed files with 6 additions and 0 deletions
|
@ -419,6 +419,12 @@ rootCmd.Flags().StringVarP(&Region, "region", "r", "", "AWS region (required)")
|
|||
rootCmd.MarkFlagRequired("region")
|
||||
```
|
||||
|
||||
Or, for persistent flags:
|
||||
```go
|
||||
rootCmd.PersistentFlags().StringVarP(&Region, "region", "r", "", "AWS region (required)")
|
||||
rootCmd.MarkPersistentFlagRequired("region")
|
||||
```
|
||||
|
||||
## Positional and Custom Arguments
|
||||
|
||||
Validation of positional arguments can be specified using the `Args` field
|
||||
|
|
Loading…
Reference in a new issue