Permalink
Browse files

move persistent flag to root

  • Loading branch information...
surajssd committed Jan 4, 2019
1 parent 26122e9 commit ab3fe4d7ecec26ca5c02cffa861941708f89a5de
Showing with 6 additions and 11 deletions.
  1. +0 −1 cmd/alpha.go
  2. +0 −1 cmd/one.go
  3. +6 −9 cmd/root.go
@@ -15,7 +15,6 @@ var alphaCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(alphaCmd)
addConfig(alphaCmd)
}

func runAlpha(cmd *cobra.Command, args []string) {
@@ -15,7 +15,6 @@ var oneCmd = &cobra.Command{

func init() {
numCmd.AddCommand(oneCmd)
addConfig(oneCmd)
}

func runOne(cmd *cobra.Command, args []string) {
@@ -20,17 +20,14 @@ func Execute() {

func init() {
cobra.OnInitialize(cobraInit)
}

func cobraInit() {
viper.AutomaticEnv()
}

func addConfig(cmd *cobra.Command) {
// add config flag
cmd.PersistentFlags().String(
rootCmd.PersistentFlags().String(
"config",
os.ExpandEnv("$HOME/.config"),
"Path to config file")
viper.BindPFlag("config", cmd.PersistentFlags().Lookup("config"))
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
}

func cobraInit() {
viper.AutomaticEnv()
}

0 comments on commit ab3fe4d

Please sign in to comment.