From 1ac0ee3ac96f996f77d83fc215beb42b3cc54d77 Mon Sep 17 00:00:00 2001 From: Marcus Kok <47163063+Marcusk19@users.noreply.github.com> Date: Wed, 24 Apr 2024 17:31:41 -0400 Subject: [PATCH] remove leading '.' in file if adding to the config (#31) --- cmd/add.go | 17 +++++++++++------ cmd/remove.go | 8 ++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index 0f218c1..add97e9 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -37,16 +37,13 @@ func runAddCommand(cmd *cobra.Command, args []string) { configSrc := args[0] dirs := strings.Split(configSrc, "/") name := dirs[len(dirs) - 1] // take the last section of the path, this should be the name + if name[0] == '.' { + name = name[1:] + } links := viper.GetStringMap("links") links[name] = configSrc viper.Set("links", links) - if !testing { - err := viper.WriteConfig() - if err != nil { - fmt.Printf("Problem updating dotctl config %s", err) - } - } dotfilePath := viper.Get("dotfile-path").(string) @@ -69,9 +66,17 @@ func runAddCommand(cmd *cobra.Command, args []string) { if strings.ToUpper(overwrite) == "Y" { addConfigToDir(fs, configSrc, dotfileDest) } + fmt.Printf("Just set up %s to link to %s\n", configSrc, dotfileDest) } else { addConfigToDir(fs, configSrc, dotfileDest) } + + if !testing { + err := viper.WriteConfig() + if err != nil { + fmt.Printf("Problem updating dotctl config %s", err) + } + } } func addConfigToDir(fs afero.Fs, configSrc, dotfileDest string) { diff --git a/cmd/remove.go b/cmd/remove.go index 300779c..9849162 100644 --- a/cmd/remove.go +++ b/cmd/remove.go @@ -60,6 +60,14 @@ func runRemoveCommand(cmd *cobra.Command, args []string) { fmt.Printf("ERROR: problem copying over dotfile(s) %s\n", err) return } + + delete(links, dotfile) + viper.Set("links", links) + err = viper.WriteConfig() + if err != nil { + fmt.Printf("ERROR: problem saving config: %s\n", err) + return + } fmt.Printf("%s symlink removed, copied files over to %s\n", dotfile, dotfileConfigPath) }