add stuff (#20)

* add ability to view list of linked configs

* hide password in input for sync command

* confirm overwrite existing configs when adding
pull/21/head
Marcus Kok 2 years ago committed by GitHub
parent 0b042d8637
commit d5b8970279
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -8,3 +8,4 @@ sandbox:
unit-test: unit-test:
TESTING=true go test -v ./test TESTING=true go test -v ./test
rm -rf test/dotctl_test 2> /dev/null

@ -7,6 +7,7 @@ import (
"strings" "strings"
"github.com/Marcusk19/dotctl/tools" "github.com/Marcusk19/dotctl/tools"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -50,6 +51,20 @@ func runAddCommand(cmd *cobra.Command, args []string) {
fmt.Printf("Will copy %s -> %s \n", configSrc, dotfileDest) fmt.Printf("Will copy %s -> %s \n", configSrc, dotfileDest)
return return
} }
_, 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?")
confirm := promptui.Prompt{
Label: "overwrite config",
IsConfirm: true,
}
overwrite, _ := confirm.Run()
if strings.ToUpper(overwrite) != "Y" {
return
}
}
err = tools.CopyDir(fs, configSrc, dotfileDest) err = tools.CopyDir(fs, configSrc, dotfileDest)
if err != nil { if err != nil {

@ -10,6 +10,12 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
func init() {
RootCmd.AddCommand(linkCommand)
linkCommand.AddCommand(listCommand)
}
var linkCommand = &cobra.Command { var linkCommand = &cobra.Command {
Use: "link", Use: "link",
Run: runLinkCommand, Run: runLinkCommand,
@ -17,9 +23,6 @@ var linkCommand = &cobra.Command {
Long: "add longer description", // TODO add longer description here Long: "add longer description", // TODO add longer description here
} }
func init() {
RootCmd.AddCommand(linkCommand)
}
func runLinkCommand(cmd *cobra.Command, args []string) { func runLinkCommand(cmd *cobra.Command, args []string) {
fs := FileSystem fs := FileSystem
@ -64,6 +67,20 @@ func runLinkCommand(cmd *cobra.Command, args []string) {
} }
} }
} }
}
var listCommand = &cobra.Command {
Use: "list",
Run: runListCommand,
Short: "list configs that should be symlinked",
Long: "add longer description", // TODO add longer description here
}
func runListCommand(cmd *cobra.Command, args []string) {
links := viper.GetStringMapString("links")
fmt.Println("Configs added:")
for configName, configPath := range links {
fmt.Printf("%s: %s\n", configName, configPath)
}
} }

@ -98,6 +98,8 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
password := promptui.Prompt{ password := promptui.Prompt{
Label: "password", Label: "password",
Validate: validateInput, Validate: validateInput,
HideEntered: true,
Mask: '*',
} }
usernameVal, err := username.Run() usernameVal, err := username.Run()

@ -14,6 +14,7 @@ import (
func TestLinkCommand(t *testing.T) { func TestLinkCommand(t *testing.T) {
oldDotfilePath := viper.GetString("dotfile-path")
setUpTesting() setUpTesting()
dotctl := cmd.RootCmd dotctl := cmd.RootCmd
actual := new(bytes.Buffer) actual := new(bytes.Buffer)
@ -32,7 +33,7 @@ func TestLinkCommand(t *testing.T) {
assert.Equal(t, expected, actual.String(), "actual differs from expected") assert.Equal(t, expected, actual.String(), "actual differs from expected")
tearDownTesting() tearDownTesting(oldDotfilePath)
} }
func setUpTesting() { func setUpTesting() {
@ -49,7 +50,7 @@ func setUpTesting() {
viper.Set("someconfig", filepath.Join(homedir, ".config/someconfig/")) viper.Set("someconfig", filepath.Join(homedir, ".config/someconfig/"))
} }
func tearDownTesting() { func tearDownTesting(oldDotfilePath string) {
fs := cmd.FileSystem viper.Set("dotfile-path", oldDotfilePath)
fs.RemoveAll("dotctl_test/") viper.WriteConfig()
} }

Loading…
Cancel
Save