-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
108 lines (97 loc) · 3.3 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"
"os"
"github.com/pgattic/canon/config"
"github.com/pgattic/canon/manager"
"github.com/pgattic/canon/referencer"
)
func displayHelp() {
fmt.Println("Usage:", os.Args[0], "[COMMAND/REFERENCE] [OPTS]")
fmt.Println()
fmt.Println("Canon Book Referencer")
fmt.Println()
fmt.Println("Commands:")
fmt.Println(" help Display this page")
fmt.Println(" install [Repo URL] Install canon package from repository")
fmt.Println(" list List installed Canon packages")
fmt.Println(" remove [Package] Remove package by shortname")
fmt.Println()
fmt.Println("If anything besides these commands is given, the input is assumed to be a book")
fmt.Println("reference, followed or preceded by any combination of these reference options:")
fmt.Println()
fmt.Println("Reference Options")
fmt.Println(" -n, --numbered Print verse/paragraph numbers before each line.")
fmt.Println(" -p, --paragraph Print the lines of text with an extra space in between")
fmt.Println(" them, as paragraphs.")
fmt.Println(" -v, --verbose Print extra information, like where the book was found.")
fmt.Println(" Useful for supplementary tools like canonmk. It is not")
fmt.Println(" recommended to use -n or -p with -v.")
fmt.Println()
fmt.Println("Canon made by Preston Corless (pgattic), free under the MIT License.")
fmt.Println("More information can be found at https://github.com/pgattic/canon")
}
func main() {
config.EnsureSetup() // Make sure there is a ~/.canon/texts/config.json file
args := os.Args
if len(args) < 2 {
fmt.Println("Usage:", args[0], "[COMMAND/REFERENCE] [OPTS]")
fmt.Println("Try \"" + args[0] + " help\" for more information.")
return
}
switch args[1] {
/* Package management arguments */
case "install":
if len(args) < 3 {
fmt.Println("Please specify a canon-formatted repository (example: \"canon install https://github.com/user/repo\")")
return
}
manager.Install(args[2])
return
case "remove":
if len(args) < 3 {
fmt.Println("Please specify a package to remove")
return
}
manager.Remove(args[2])
return
case "list":
manager.List()
return
case "help":
displayHelp()
return
/* reference verse(s) */
default:
var execFlags referencer.Flags
var refIdx int // index of the args that is the verse index (flags could be before or after the verse ref)
for i := len(args)-1; i >= 1; i-- {
if args[i][0] == '-' {
if args[i][1] == '-' { // args starting with "--"
switch args[i] {
case "--paragraph":
execFlags.Paragraph = true
case "--verbose":
execFlags.Verbose = true
case "--numbered":
execFlags.VerseNumbers = true
}
continue
}
for ch := 1; ch < len(args[i]); ch++ {
switch args[i][ch] { // Execution flags
case 'p':
execFlags.Paragraph = true
case 'v':
execFlags.Verbose = true
case 'n':
execFlags.VerseNumbers = true
}
}
} else {
refIdx = i
}
}
referencer.ParseRef(args[refIdx], execFlags)
}
}