From 142dfb15a8b9122dd6543adc769cbf59b976d793 Mon Sep 17 00:00:00 2001 From: Adam Demuri Date: Wed, 14 Oct 2020 09:53:09 -0600 Subject: [PATCH] Add example for making persistent flags required (#1135) --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index b8cda7a..3cf1b25 100644 --- a/README.md +++ b/README.md @@ -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