Skip to content
Myr

Change generator to require opting in to viper.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Steve Francia · committed by Steve Francia · parent c0dd5cd · Browse files · 2 files+5 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+5 added−2 removed

  • other:+5 added−2 removed

2 files+5 added−2 removed

modified:cobra/cmd/add_test.go+3 added
2 unmodified lines
3import (4 "fmt"5 "os"6 "testing"78 "github.com/spf13/viper"9)1011func TestGoldenAddCmd(t *testing.T) {12 viper.Set("useViper", true)13 command := &Command{14 CmdName: "test",15 CmdParent: parentName,16 Project: getProject(),
37 unmodified lines
modified:cobra/cmd/root.go+2 added-2 removed
1// Copyright © 2015 Steve Francia <spf@spf13.com>.1// Copyright © 2021 Steve Francia <spf@spf13.com>.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at
39 unmodified lines
4546 rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")47 rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution")48 rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")49 rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")49 rootCmd.PersistentFlags().Bool("viper", false, "use Viper for configuration")50 cobra.CheckErr(viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author")))51 cobra.CheckErr(viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper")))52 viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>")53 viper.SetDefault("license", "apache")
26 unmodified lines