|
|
|
@ -7,6 +7,7 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var linkCommand = &cobra.Command {
|
|
|
|
var linkCommand = &cobra.Command {
|
|
|
|
@ -21,16 +22,20 @@ func init() {
|
|
|
|
func runLinkCommand(cmd *cobra.Command, args []string) {
|
|
|
|
func runLinkCommand(cmd *cobra.Command, args []string) {
|
|
|
|
fs := UseFilesystem()
|
|
|
|
fs := UseFilesystem()
|
|
|
|
fmt.Println("Symlinking dotfiles...")
|
|
|
|
fmt.Println("Symlinking dotfiles...")
|
|
|
|
entries, err := afero.ReadDir(fs, DotfilePath)
|
|
|
|
dotfileRoot := viper.Get("dotfile-path").(string)
|
|
|
|
|
|
|
|
entries, err := afero.ReadDir(fs, dotfileRoot)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, entry := range(entries) {
|
|
|
|
for _, entry := range(entries) {
|
|
|
|
if entry.Name() == ".git" {
|
|
|
|
configName := entry.Name()
|
|
|
|
|
|
|
|
if configName == ".git" || configName == "bender" {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dotPath := filepath.Join(DotfilePath, entry.Name())
|
|
|
|
dotPath := filepath.Join(dotfileRoot, entry.Name())
|
|
|
|
configPath := filepath.Join(ConfigPath, entry.Name())
|
|
|
|
|
|
|
|
|
|
|
|
configPath := viper.Get(configName).(string)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// destination needs to be removed before symlink
|
|
|
|
// destination needs to be removed before symlink
|
|
|
|
if(DryRun) {
|
|
|
|
if(DryRun) {
|
|
|
|
@ -40,10 +45,16 @@ func runLinkCommand(cmd *cobra.Command, args []string) {
|
|
|
|
fs.RemoveAll(configPath)
|
|
|
|
fs.RemoveAll(configPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testing := viper.Get("testing")
|
|
|
|
|
|
|
|
|
|
|
|
if(DryRun) {
|
|
|
|
if(DryRun) {
|
|
|
|
log.Printf("Will link %s -> %s\n", dotPath, configPath)
|
|
|
|
log.Printf("Will link %s -> %s\n", configPath, dotPath)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
err = afero.OsFs.SymlinkIfPossible(afero.OsFs{}, dotPath, configPath)
|
|
|
|
if(testing == "true") {
|
|
|
|
|
|
|
|
fmt.Fprintf(cmd.OutOrStdout(), "%s,%s", configPath, dotPath)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
err = afero.OsFs.SymlinkIfPossible(afero.OsFs{}, dotPath, configPath)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Cannot symlink %s: %s", entry.Name(), err.Error())
|
|
|
|
log.Fatalf("Cannot symlink %s: %s", entry.Name(), err.Error())
|
|
|
|
|