You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dotctl/cmd/link.go

44 lines
886 B
Go

package cmd
import (
"fmt"
"log"
"path/filepath"
"github.com/spf13/afero"
"github.com/spf13/cobra"
)
func init() {
RootCmd.AddCommand(linkCommand)
}
var linkCommand = &cobra.Command {
Use: "link",
Run: runLinkCommand,
}
func runLinkCommand(cmd *cobra.Command, args []string) {
fmt.Println("Symlinking dotfiles...")
entries, err := afero.ReadDir(fs, DotfilePath)
if err != nil {
log.Fatal(err)
}
for _, entry := range(entries) {
if entry.Name() == ".git" {
continue
}
dotPath := filepath.Join(DotfilePath, entry.Name())
configPath := filepath.Join(ConfigPath, entry.Name())
// destination needs to be removed before symlink
fs.RemoveAll(configPath)
err = afero.OsFs.SymlinkIfPossible(afero.OsFs{}, dotPath, configPath)
if err != nil {
log.Fatalf("Cannot symlink %s: %s", entry.Name(), err.Error())
}
}
}