From 42275369e01b634cb3419d34aab765f2e19c5d57 Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Tue, 6 Jun 2023 21:20:13 -0400 Subject: [PATCH] viper binding now flows into subcommands --- cmd/obp/cmd/root.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/obp/cmd/root.go b/cmd/obp/cmd/root.go index 2c0adc8..b85962d 100644 --- a/cmd/obp/cmd/root.go +++ b/cmd/obp/cmd/root.go @@ -47,13 +47,15 @@ func init() { // will be global for your application. rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "~/.obp.toml", "config file") + rootCmd.PersistentFlags().StringVar(&vault, "vault", "", "vault root directory") rootCmd.MarkPersistentFlagRequired("vault") + rootCmd.PersistentFlags().StringVar(&format, "format", "markdown", "output format [markdown, json, csv]") rootCmd.MarkPersistentFlagRequired("format") - viper.BindPFlag("format", validateCmd.Flags().Lookup("format")) - viper.BindPFlag("vault", validateCmd.Flags().Lookup("vault")) + viper.BindPFlag("format", rootCmd.PersistentFlags().Lookup("format")) + viper.BindPFlag("vault", rootCmd.PersistentFlags().Lookup("vault")) // Cobra also supports local flags, which will only run // when this action is called directly.