Skip to content

Commit

Permalink
Merge pull request #26 from intercube/bugfix/DEV-320
Browse files Browse the repository at this point in the history
  • Loading branch information
JKetelaar authored Mar 5, 2022
2 parents 4c39e09 + 9ca14db commit f2f158a
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions cmd/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
)

var override = false
var mapCmd = &cobra.Command{
Use: "map",
Short: "Maps files based on config yaml file",
Expand All @@ -33,18 +34,35 @@ var mapCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(mapCmd)
mapCmd.PersistentFlags().BoolVarP(&override, "override", "o", false, "Overrides existing destination file")
}

func symlink(from string, to string) {
if !fileExists(to) {
err := os.Symlink(from, to)
if err != nil {
panic(fmt.Errorf("Unable to map: %s \n", err))
if !fileExists(from) {
fmt.Print(fmt.Errorf("Origin file %v does not exists\n", to))
} else {
if !fileExists(to) || override {
if override {
if destination, err := os.Lstat(to); err == nil {
if destination.IsDir() {
os.RemoveAll(to)
fmt.Printf("Removed directory %v\n", to)
} else {
os.Remove(to)
fmt.Printf("Removed file %v\n", to)
}
}
}

err := os.Symlink(from, to)
if err != nil {
panic(fmt.Errorf("Unable to map: %s \n", err))
} else {
fmt.Printf("Mapped %v to %v\n", from, to)
}
} else {
fmt.Printf("Mapped %v to %v\n", from, to)
fmt.Print(fmt.Errorf("Destination file %v already exists\n", to))
}
} else {
fmt.Print(fmt.Errorf("Destination file %v already exists\n", to))
}
}

Expand Down

0 comments on commit f2f158a

Please sign in to comment.