From dcf42b25f7f1980135e744f099ecbbc6ec85eadc Mon Sep 17 00:00:00 2001 From: Steve Francia Date: Thu, 1 Jul 2021 17:40:39 -0400 Subject: [PATCH] Change generator to require opting in to viper. Cobra and Viper are great together, but it's not uncommon to use them apart. New Cobra users don't know better and including Viper by default adds complexity to the skeleton. --- cobra/cmd/add_test.go | 3 +++ cobra/cmd/root.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cobra/cmd/add_test.go b/cobra/cmd/add_test.go index 0b32ca67..c9b185b5 100644 --- a/cobra/cmd/add_test.go +++ b/cobra/cmd/add_test.go @@ -4,9 +4,12 @@ import ( "fmt" "os" "testing" + + "github.com/spf13/viper" ) func TestGoldenAddCmd(t *testing.T) { + viper.Set("useViper", true) command := &Command{ CmdName: "test", CmdParent: parentName, diff --git a/cobra/cmd/root.go b/cobra/cmd/root.go index 350df103..ae961bea 100644 --- a/cobra/cmd/root.go +++ b/cobra/cmd/root.go @@ -1,4 +1,4 @@ -// Copyright © 2015 Steve Francia . +// Copyright © 2021 Steve Francia . // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)") rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution") rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project") - rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration") + rootCmd.PersistentFlags().Bool("viper", false, "use Viper for configuration") cobra.CheckErr(viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author"))) cobra.CheckErr(viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper"))) viper.SetDefault("author", "NAME HERE ")