remove leading '.' in file if adding to the config

pull/31/head
Marcus Kok 2 years ago
parent 289dba2eb9
commit 8ffea5d6a0

@ -37,16 +37,13 @@ func runAddCommand(cmd *cobra.Command, args []string) {
configSrc := args[0] configSrc := args[0]
dirs := strings.Split(configSrc, "/") dirs := strings.Split(configSrc, "/")
name := dirs[len(dirs) - 1] // take the last section of the path, this should be the name 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 := viper.GetStringMap("links")
links[name] = configSrc links[name] = configSrc
viper.Set("links", links) 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) dotfilePath := viper.Get("dotfile-path").(string)
@ -69,9 +66,17 @@ func runAddCommand(cmd *cobra.Command, args []string) {
if strings.ToUpper(overwrite) == "Y" { if strings.ToUpper(overwrite) == "Y" {
addConfigToDir(fs, configSrc, dotfileDest) addConfigToDir(fs, configSrc, dotfileDest)
} }
fmt.Printf("Just set up %s to link to %s\n", configSrc, dotfileDest)
} else { } else {
addConfigToDir(fs, configSrc, dotfileDest) 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) { func addConfigToDir(fs afero.Fs, configSrc, dotfileDest string) {

@ -61,6 +61,14 @@ func runRemoveCommand(cmd *cobra.Command, args []string) {
return 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) fmt.Printf("%s symlink removed, copied files over to %s\n", dotfile, dotfileConfigPath)
} }

Loading…
Cancel
Save