add "add-default-config" flag

Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2026-05-18 23:31:49 +02:00
parent 615093bd8b
commit 789a513469
3 changed files with 26 additions and 2 deletions
+10
View File
@@ -74,6 +74,16 @@ func Load(path string) error {
return viper.Unmarshal(Global)
}
func WriteDefaultConfig(path string) error {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return fmt.Errorf("create config dir: %w", err)
}
if err := os.WriteFile(path, defaultConfig, 0o644); err != nil {
return fmt.Errorf("write config: %w", err)
}
return nil
}
func ExpandPath(p string) string {
if strings.HasPrefix(p, "~/") {
home, err := os.UserHomeDir()