parent
4d6b96b79a
commit
d313e46181
15
cmd/root.go
15
cmd/root.go
@ -25,6 +25,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@ -61,10 +62,24 @@ func Execute() {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
|
ensureConfigDir()
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.workon.yaml)")
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.workon.yaml)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensureConfigDir ensures ~/.workon/ exists
|
||||||
|
func ensureConfigDir() {
|
||||||
|
home, err := homedir.Dir()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
configDir := path.Join(home, ".workon")
|
||||||
|
if _, err = os.Stat(configDir); os.IsNotExist(err) {
|
||||||
|
os.Mkdir(configDir, 0755)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// initConfig reads in config file and ENV variables if set.
|
// initConfig reads in config file and ENV variables if set.
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user