File tree Expand file tree Collapse file tree 4 files changed +20
-7
lines changed
vendor/github.com/mitchellh Expand file tree Collapse file tree 4 files changed +20
-7
lines changed Original file line number Diff line number Diff line change 11[submodule "vendor/github.com/xanzy/go-gitlab "]
22 path = vendor/github.com/xanzy/go-gitlab
33 url = https://github.com/xanzy/go-gitlab
4+ [submodule "vendor/github.com/mitchellh/go-homedir "]
5+ path = vendor/github.com/mitchellh/go-homedir
6+ url = https://github.com/mitchellh/go-homedir
Original file line number Diff line number Diff line change 1616 repo , repourl , token string
1717 user , password string
1818 verbose bool
19+ configName = ".gitlab-cli"
1920)
2021
2122// RootCmd represents the base command when called without any subcommands
@@ -67,9 +68,9 @@ func initConfig() {
6768 viper .SetConfigFile (cfgFile )
6869 }
6970
70- viper .SetConfigName (".gitlab-cli" ) // name of config file (without extension)
71- viper .AddConfigPath ("$HOME" ) // adding home directory as first search path
72- viper .AutomaticEnv () // read in environment variables that match
71+ viper .SetConfigName (configName ) // name of config file (without extension)
72+ viper .AddConfigPath ("$HOME" ) // adding home directory as first search path
73+ viper .AutomaticEnv () // read in environment variables that match
7374 viper .ConfigFileUsed ()
7475
7576 // If a config file is found, read it in.
Original file line number Diff line number Diff line change 11package cmd
22
33import (
4- "os"
5-
64 "fmt"
7-
5+ "os"
6+ "path/filepath"
87 "strings"
98
9+ "github.com/mitchellh/go-homedir"
1010 "github.com/spf13/viper"
1111 "gopkg.in/yaml.v2"
1212)
1313
1414func SaveViperConfig () error {
15- f , err := os .Create (viper .ConfigFileUsed ())
15+ filename := viper .ConfigFileUsed ()
16+ if filename == "" {
17+ hdir , err := homedir .Dir ()
18+ if err != nil {
19+ return err
20+ }
21+ filename = filepath .Join (hdir , configName + ".yml" )
22+ }
23+ f , err := os .Create (filename )
1624 if err != nil {
1725 return err
1826 }
You can’t perform that action at this time.
0 commit comments