Skip to content

Commit 142dfb1

Browse files
authored
Add example for making persistent flags required (#1135)
1 parent 723d0c3 commit 142dfb1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ rootCmd.Flags().StringVarP(&Region, "region", "r", "", "AWS region (required)")
419419
rootCmd.MarkFlagRequired("region")
420420
```
421421

422+
Or, for persistent flags:
423+
```go
424+
rootCmd.PersistentFlags().StringVarP(&Region, "region", "r", "", "AWS region (required)")
425+
rootCmd.MarkPersistentFlagRequired("region")
426+
```
427+
422428
## Positional and Custom Arguments
423429

424430
Validation of positional arguments can be specified using the `Args` field

0 commit comments

Comments
 (0)