-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (59 loc) · 1.42 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"errors"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/shrimp332/tidy/linker"
)
var (
version = "v1.2.0"
set bool
unset bool
force bool
)
func main() {
rootCmd := &cobra.Command{
Use: "tidy",
Short: "Tidy Dotfile Linker " + version,
RunE: func(cmd *cobra.Command, args []string) error {
var err error
if set {
for _, arg := range args {
err = linker.SetSym(arg, force)
if errors.Is(err, os.ErrNotExist) {
fmt.Fprintln(os.Stderr, arg, "does not have a .tidy.json file")
fmt.Fprintln(os.Stderr, err)
err = nil
} else if err != nil {
return err
}
}
} else if unset {
for _, arg := range args {
err = linker.UnsetSym(arg)
if errors.Is(err, os.ErrNotExist) {
fmt.Fprintln(os.Stderr, arg, "does not have a .tidy.json file")
err = nil
} else if err != nil {
return err
}
}
} else {
cmd.Help()
}
return err
},
Example: "tidy [-s | -u] [directory | *]",
}
rootCmd.Flags().
BoolVarP(&set, "set", "s", false, "use to create symlinks, mutually exclusive with unset")
rootCmd.Flags().
BoolVarP(&unset, "unset", "u", false, "use to remove symlinks, mutually exclusive with set")
rootCmd.Flags().
BoolVarP(&force, "force", "f", false, "overwrite existing files")
rootCmd.MarkFlagsMutuallyExclusive("set", "unset")
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}