forked from jesseduffield/horcrux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (56 loc) · 1.44 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
package main
import (
"log"
"os"
"github.com/jesseduffield/horcrux/pkg/commands"
)
func main() {
// I'd use `flaggy` but I like the idea of this repo having no dependencies
// Unfortunately that means I'm awkwardly making use of the standard flag package
if len(os.Args) < 2 {
usage()
}
if os.Args[1] == "bind" {
var dir string
if len(os.Args) == 2 {
dir = "."
} else {
dir = os.Args[2]
}
paths, err := commands.GetHorcruxPathsInDir(dir)
if err != nil {
log.Fatal(err)
}
overwrite := false
for {
if err := commands.Bind(paths, "", overwrite); err != nil {
if err != os.ErrExist {
log.Fatal(err)
}
overwriteResponse := commands.Prompt("A file already exists at destination. Overwrite? (Y/N):")
if overwriteResponse == "Y" || overwriteResponse == "y" || overwriteResponse == "yes" {
overwrite = true
} else {
log.Fatal("You have chosen not to overwrite the file. Cancelling.")
}
} else {
break
}
}
return
}
if os.Args[len(os.Args)-2] == "split" {
if len(os.Args) == 2 {
usage()
}
path := os.Args[len(os.Args)-1]
if err := commands.SplitWithPrompt(path); err != nil {
log.Fatal(err)
}
return
}
usage()
}
func usage() {
log.Fatal("usage: `horcrux bind [<directory>]` | `horcrux [-t] [-n] split <filename>`\n-n: number of horcruxes to make\n-t: number of horcruxes required to resurrect the original file\nexample: horcrux -t 3 -n 5 split diary.txt")
}