-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
106 lines (90 loc) · 2.17 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/urfave/cli/v2"
)
const VERSION = "0.3.0"
func main() {
app := &cli.App{
Name: "dotcopy",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "silent",
Usage: "Silence all output to stdout. Use `-s -d` to silence all output.",
Aliases: []string{"s"},
Value: false,
},
&cli.BoolFlag{
Name: "disable-notifications",
Usage: "Disable system notifications",
Aliases: []string{"d", "n"},
Value: false,
},
},
Usage: "Builds your dotfiles. See https://dotcopy.firesquid.co",
Action: func(c *cli.Context) error {
logger := MakeRealLogger(!c.Bool("disable-notifications"), !c.Bool("silent"))
output := Dotcopy(logger)
if output == "" {
logger.SuccessfulBuild()
} else {
logger.Error(output)
}
return nil
},
Commands: []*cli.Command{
{
Name: "init",
Usage: "Initializes a basic localconfig",
Action: func(c *cli.Context) error {
fmt.Println("Not implemented yet")
return nil
},
},
{
Name: "version",
Usage: "Prints the version of dotcopy",
Action: func(c *cli.Context) error {
fmt.Println("v" + VERSION)
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
// the core of dotcopy
// compiles and copies your dotfiles to their appropriate location
func Dotcopy(logger Logger) string {
fs := MakeRealFilesystem()
localConfig, err := ParseLocalConfig(fs)
if err != nil {
return "Error parsing localconfig. Does ~/.config/dotcopy/localconfig.yaml exist?"
}
dotfiles, err := ParseDotfiles(fs, localConfig)
if err != nil {
return "Error parsing dotfiles"
}
globalVars, err := ParseGlobalVars(fs, localConfig)
if err != nil {
log.Println(err)
}
for _, dotfile := range dotfiles {
text, filepath := CompileDotfile(dotfile, globalVars)
err := fs.WriteFile(filepath, text)
if err != nil {
return "Error writing file"
}
slotfileLog := dotfile.SlotFilepath
if slotfileLog != "" {
slotfileLog = "No slotfile"
}
logger.Info(strings.Join([]string{"Compiled:", dotfile.TemplateFilepath, "+", slotfileLog, "-->", filepath}, " "))
}
return ""
}