Skip to content

Commit

Permalink
Default to ~/.config/gmailctl for the config dir.
Browse files Browse the repository at this point in the history
This is a minimal fix for mbrt#144
  • Loading branch information
lgarron committed Mar 21, 2024
1 parent 086c6a2 commit 8a2dcc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/gmailctl/cmd/init_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func handleCfgDir() error {
}
}

fmt.Printf("%s", cfgDir)

// Create default config files
cfgFile := path.Join(cfgDir, "config.jsonnet")
if err := createDefault(cfgFile, data.DefaultConfig()); err != nil {
Expand Down
8 changes: 6 additions & 2 deletions cmd/gmailctl/cmd/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd.PersistentFlags().StringVar(&cfgDir, "config", "", "config directory (default is $HOME/.gmailctl)")
rootCmd.PersistentFlags().StringVar(&cfgDir, "config", "", "config directory (default is $HOME/.gmailctl if already present, else $HOME/.config/gmailctl)")
}

// initConfig reads in config file and ENV variables if set.
Expand All @@ -65,6 +65,10 @@ func initConfig() {
fmt.Println(err)
os.Exit(1)
}
cfgDir = path.Join(usr.HomeDir, ".gmailctl")
if _, err := os.Stat(path.Join(usr.HomeDir, ".gmailctl")); err != nil && os.IsNotExist(err) {
cfgDir = path.Join(usr.HomeDir, ".config", "gmailctl")
} else {
cfgDir = path.Join(usr.HomeDir, ".gmailctl")
}
}
}

0 comments on commit 8a2dcc8

Please sign in to comment.