From f1d4e0a8d51d0417a59679b3469361da96d30c50 Mon Sep 17 00:00:00 2001 From: Mariano Uvalle Date: Fri, 10 Nov 2023 16:42:56 +0000 Subject: [PATCH] Default config dir. --- cmd/cli/root.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/cli/root.go b/cmd/cli/root.go index 08d4d64..8d0cbbc 100644 --- a/cmd/cli/root.go +++ b/cmd/cli/root.go @@ -1,7 +1,10 @@ package main import ( + "fmt" "log" + "os" + "path" "github.com/AYM1607/ccclip/internal/configfile" "github.com/spf13/cobra" @@ -18,9 +21,13 @@ var rootCmd = &cobra.Command{ } func init() { - rootCmd.PersistentFlags().StringVarP(&configfile.Path, "config-path", "c", "", "directory where to store the config file") + homeDir, err := os.UserHomeDir() + if err != nil { + panic(fmt.Sprintf("could not locate home directory: %s", err.Error())) + } + defualtConfigPath := path.Join(homeDir, ".config", "ccclip") - rootCmd.MarkPersistentFlagRequired("config-path") + rootCmd.PersistentFlags().StringVar(&configfile.Path, "config-dir", defualtConfigPath, "location of the ccclip.yaml configuration file") } // Execute adds all child commands to the root command and sets flags appropriately.