switch default corso config location (#836)
## Description Swaps the default corso config location from $HOME to /app/corso in order to align with docs. ## Type of change - [x] 🐹 Trivial/Minor ## Issue(s) * #718 ## Test Plan - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
1295750206
commit
02ad1a86b8
@ -29,22 +29,25 @@ const (
|
||||
TenantIDKey = "tenantid"
|
||||
)
|
||||
|
||||
var configFilePath string
|
||||
var (
|
||||
configFilePath string
|
||||
defaultDir = filepath.Join("app", "corso")
|
||||
)
|
||||
|
||||
// adds the persistent flag --config-file to the provided command.
|
||||
func AddConfigFlags(cmd *cobra.Command) {
|
||||
fs := cmd.PersistentFlags()
|
||||
|
||||
homeDir, err := os.UserHomeDir()
|
||||
_, err := os.Stat(defaultDir)
|
||||
if err != nil {
|
||||
Err(cmd.Context(), "finding $HOME directory (default) for config file")
|
||||
Err(cmd.Context(), "finding "+defaultDir+" directory (default) for config file")
|
||||
}
|
||||
|
||||
fs.StringVar(
|
||||
&configFilePath,
|
||||
"config-file",
|
||||
filepath.Join(homeDir, ".corso.toml"),
|
||||
"config file (default is $HOME/.corso)")
|
||||
filepath.Join(defaultDir, ".corso.toml"),
|
||||
"config file (default is "+defaultDir+".corso.toml)")
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
@ -70,13 +73,13 @@ func initWithViper(vpr *viper.Viper, configFP string) error {
|
||||
// Configure default config file location
|
||||
if configFP == "" {
|
||||
// Find home directory.
|
||||
home, err := os.UserHomeDir()
|
||||
_, err := os.Stat(defaultDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Search config in home directory with name ".corso" (without extension).
|
||||
vpr.AddConfigPath(home)
|
||||
vpr.AddConfigPath(defaultDir)
|
||||
vpr.SetConfigType("toml")
|
||||
vpr.SetConfigName(".corso")
|
||||
|
||||
|
||||
@ -28,6 +28,10 @@ func SetRootCmd(ctx context.Context, root *cobra.Command) context.Context {
|
||||
// Gets the root cobra command from the context.
|
||||
// If no command is found, returns a new, blank command.
|
||||
func getRootCmd(ctx context.Context) *cobra.Command {
|
||||
if ctx == nil {
|
||||
return &cobra.Command{}
|
||||
}
|
||||
|
||||
cmdIface := ctx.Value(rootCmdCtx{})
|
||||
cmd, ok := cmdIface.(*cobra.Command)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user