|
|
|
|
@ -3,6 +3,7 @@ package cmd
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
@ -14,16 +15,19 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
addCommand.Flags().BoolVar(&absolutePath, "absolute", false, "absolute path of config")
|
|
|
|
|
RootCmd.AddCommand(addCommand)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var addCommand = &cobra.Command{
|
|
|
|
|
Use: "add",
|
|
|
|
|
Short: "Adds config to be tracked by dotctl",
|
|
|
|
|
Long: "TODO: add longer description", // TODO add more description
|
|
|
|
|
Long: "will copy files passed as argument to the dotfiles directory and symlink them", // TODO add more description
|
|
|
|
|
Run: runAddCommand,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var absolutePath bool
|
|
|
|
|
|
|
|
|
|
func runAddCommand(cmd *cobra.Command, args []string) {
|
|
|
|
|
fs := FileSystem
|
|
|
|
|
|
|
|
|
|
@ -35,6 +39,12 @@ func runAddCommand(cmd *cobra.Command, args []string) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configSrc := args[0]
|
|
|
|
|
|
|
|
|
|
if !absolutePath {
|
|
|
|
|
cwd, _ := os.Getwd()
|
|
|
|
|
configSrc = cwd + "/" + configSrc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dirs := strings.Split(configSrc, "/")
|
|
|
|
|
name := dirs[len(dirs)-1] // take the last section of the path, this should be the name
|
|
|
|
|
if name[0] == '.' {
|
|
|
|
|
@ -57,7 +67,7 @@ func runAddCommand(cmd *cobra.Command, args []string) {
|
|
|
|
|
_, err := fs.Stat(dotfileDest)
|
|
|
|
|
if err == nil {
|
|
|
|
|
fmt.Printf("Looks like %s exists in current dotfile directory\n", dotfileDest)
|
|
|
|
|
fmt.Println("Do you want to overwrite it?")
|
|
|
|
|
fmt.Printf("Do you want to overwrite it with what is in %s?\n", configSrc)
|
|
|
|
|
confirm := promptui.Prompt{
|
|
|
|
|
Label: "overwrite config",
|
|
|
|
|
IsConfirm: true,
|
|
|
|
|
@ -66,12 +76,20 @@ 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 !DryRun {
|
|
|
|
|
// symlink the copied dotfile destination back to the config src
|
|
|
|
|
fs.RemoveAll(configSrc)
|
|
|
|
|
linkPaths(dotfileDest, configSrc)
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Println("Files were not symlinked")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !testing {
|
|
|
|
|
// write to the config to persist changes
|
|
|
|
|
err := viper.WriteConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("Problem updating dotctl config %s", err)
|
|
|
|
|
|