1
1
package cmd
2
2
3
3
import (
4
- "fmt"
5
4
"os"
6
5
7
6
"github.com/fosskey/cli/internal/util"
8
7
"github.com/spf13/cobra"
9
- "github.com/spf13/viper"
10
8
)
11
9
12
- var cfgFile string
13
-
14
10
// rootCmd represents the base command when called without any subcommands
15
11
var rootCmd = & cobra.Command {
16
12
Use : "foss" ,
@@ -36,8 +32,6 @@ func Execute() {
36
32
}
37
33
38
34
func init () {
39
- cobra .OnInitialize (initConfig )
40
-
41
35
// Here you will define your flags and configuration settings.
42
36
// Cobra supports persistent flags, which, if defined here,
43
37
// will be global for your application.
@@ -52,27 +46,3 @@ func init() {
52
46
// when this action is called directly.
53
47
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
54
48
}
55
-
56
- // initConfig reads in config file and ENV variables if set.
57
- func initConfig () {
58
- if cfgFile != "" {
59
- // Use config file from the flag.
60
- viper .SetConfigFile (cfgFile )
61
- } else {
62
- // Find home directory.
63
- home , err := os .UserHomeDir ()
64
- cobra .CheckErr (err )
65
-
66
- // Search config in home directory with name ".foss" (without extension).
67
- viper .AddConfigPath (home )
68
- viper .SetConfigType ("yaml" )
69
- viper .SetConfigName (".foss" )
70
- }
71
-
72
- viper .AutomaticEnv () // read in environment variables that match
73
-
74
- // If a config file is found, read it in.
75
- if err := viper .ReadInConfig (); err == nil {
76
- fmt .Fprintln (os .Stderr , "Using config file:" , viper .ConfigFileUsed ())
77
- }
78
- }
0 commit comments