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:
Keepers 2022-09-14 16:58:56 -06:00 committed by GitHub
parent 1295750206
commit 02ad1a86b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -29,22 +29,25 @@ const (
TenantIDKey = "tenantid" TenantIDKey = "tenantid"
) )
var configFilePath string var (
configFilePath string
defaultDir = filepath.Join("app", "corso")
)
// adds the persistent flag --config-file to the provided command. // adds the persistent flag --config-file to the provided command.
func AddConfigFlags(cmd *cobra.Command) { func AddConfigFlags(cmd *cobra.Command) {
fs := cmd.PersistentFlags() fs := cmd.PersistentFlags()
homeDir, err := os.UserHomeDir() _, err := os.Stat(defaultDir)
if err != nil { 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( fs.StringVar(
&configFilePath, &configFilePath,
"config-file", "config-file",
filepath.Join(homeDir, ".corso.toml"), filepath.Join(defaultDir, ".corso.toml"),
"config file (default is $HOME/.corso)") "config file (default is "+defaultDir+".corso.toml)")
} }
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
@ -70,13 +73,13 @@ func initWithViper(vpr *viper.Viper, configFP string) error {
// Configure default config file location // Configure default config file location
if configFP == "" { if configFP == "" {
// Find home directory. // Find home directory.
home, err := os.UserHomeDir() _, err := os.Stat(defaultDir)
if err != nil { if err != nil {
return err return err
} }
// Search config in home directory with name ".corso" (without extension). // Search config in home directory with name ".corso" (without extension).
vpr.AddConfigPath(home) vpr.AddConfigPath(defaultDir)
vpr.SetConfigType("toml") vpr.SetConfigType("toml")
vpr.SetConfigName(".corso") vpr.SetConfigName(".corso")

View File

@ -28,6 +28,10 @@ func SetRootCmd(ctx context.Context, root *cobra.Command) context.Context {
// Gets the root cobra command from the context. // Gets the root cobra command from the context.
// If no command is found, returns a new, blank command. // If no command is found, returns a new, blank command.
func getRootCmd(ctx context.Context) *cobra.Command { func getRootCmd(ctx context.Context) *cobra.Command {
if ctx == nil {
return &cobra.Command{}
}
cmdIface := ctx.Value(rootCmdCtx{}) cmdIface := ctx.Value(rootCmdCtx{})
cmd, ok := cmdIface.(*cobra.Command) cmd, ok := cmdIface.(*cobra.Command)