11package cmd
22
33import (
4- "fmt"
54 "os"
65
76 "github.com/fosskey/cli/internal/util"
87 "github.com/spf13/cobra"
9- "github.com/spf13/viper"
108)
119
12- var cfgFile string
13-
1410// rootCmd represents the base command when called without any subcommands
1511var rootCmd = & cobra.Command {
1612 Use : "foss" ,
@@ -36,8 +32,6 @@ func Execute() {
3632}
3733
3834func init () {
39- cobra .OnInitialize (initConfig )
40-
4135 // Here you will define your flags and configuration settings.
4236 // Cobra supports persistent flags, which, if defined here,
4337 // will be global for your application.
@@ -52,27 +46,3 @@ func init() {
5246 // when this action is called directly.
5347 // rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
5448}
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