add dry run option for link

pull/10/head
Marcus Kok 2 years ago
parent 959e2ff2c9
commit 7ea68f71e3

@ -9,15 +9,18 @@ import (
"github.com/spf13/cobra"
)
func init() {
RootCmd.AddCommand(linkCommand)
}
var linkCommand = &cobra.Command {
Use: "link",
Run: runLinkCommand,
}
var DryRun bool
func init() {
RootCmd.AddCommand(linkCommand)
linkCommand.Flags().BoolVarP(&DryRun, "dry-run", "d", false, "Only output which symlinks will be created")
}
func runLinkCommand(cmd *cobra.Command, args []string) {
fs := UseFilesystem()
fmt.Println("Symlinking dotfiles...")
@ -33,9 +36,18 @@ func runLinkCommand(cmd *cobra.Command, args []string) {
configPath := filepath.Join(ConfigPath, entry.Name())
// destination needs to be removed before symlink
if(DryRun) {
log.Printf("Existing directory %s will be removed\n", configPath)
} else {
fs.RemoveAll(configPath)
}
if(DryRun) {
log.Printf("Will link %s -> %s\n", dotPath, configPath)
} else {
err = afero.OsFs.SymlinkIfPossible(afero.OsFs{}, dotPath, configPath)
}
if err != nil {
log.Fatalf("Cannot symlink %s: %s", entry.Name(), err.Error())
}

Loading…
Cancel
Save