-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
67 lines (55 loc) · 2 KB
/
Copy pathcli.go
File metadata and controls
67 lines (55 loc) · 2 KB
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
67
package main
import (
"fmt"
"log"
"strings"
"github.com/solerf/dtm/dotfile"
)
func showResult(action string, status []dotfile.OperationStatus) {
template := "%s: [%v] to [%v]"
var sb strings.Builder
sb.WriteString(fmt.Sprintf("%s summary:\n", action))
for _, s := range status {
if s.Error != nil {
sb.WriteString(fmt.Sprintf("%s: %v\n", fmt.Sprintf(template, s.Status, s.Dotfile.Key, s.Dotfile.SymLink), s.Error))
continue
}
sb.WriteString(fmt.Sprintf(template, s.Status, s.Dotfile.Key, s.Dotfile.SymLink) + "\n")
}
log.Println(sb.String())
}
type InstallCmd struct {
Profiles []string `arg:"" required:"" short:"p" help:"Profiles name to be installed (Profiles name will be matched against dotfiles structure). The order defines the priority"`
Source string `optional:"" short:"s" type:"path" default:"$PWD" env:"PWD" help:"Path to source directory with dotfiles to be installed."`
Target string `optional:"" short:"t" type:"path" default:"$HOME" env:"HOME" help:"Path to target directory where dotfiles will be installed."`
}
func (i *InstallCmd) Run() error {
status, err := dotfile.Install(i.Source, i.Target, i.Profiles...)
if err != nil {
return err
}
showResult("install", status)
return nil
}
type UninstallCmd struct {
Target string `optional:"" short:"t" type:"path" default:"$HOME" env:"HOME" help:"Path to target directory where dotfiles are installed."`
}
func (u *UninstallCmd) Run() error {
status, err := dotfile.Uninstall(u.Target)
if err != nil {
return err
}
showResult("uninstall", status)
return nil
}
type ShowCmd struct {
Target string `optional:"" short:"t" type:"path" default:"$HOME" env:"HOME" help:"Path to target directory where dotfiles are installed."`
}
func (s *ShowCmd) Run() error {
return dotfile.Show(s.Target)
}
var cmd struct {
Install InstallCmd `cmd:"" help:"Install dotfiles."`
Uninstall UninstallCmd `cmd:"" help:"Uninstall dotfiles previously installed."`
Show ShowCmd `cmd:"" help:"Show current dotfiles installed."`
}