-
Notifications
You must be signed in to change notification settings - Fork 58
/
main.go
65 lines (56 loc) · 1.35 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
package main
import (
"fmt"
"os"
"strings"
"github.com/fatih/color"
flag "github.com/juju/gnuflag"
"github.com/ok-borg/borg/commands"
"github.com/ok-borg/borg/conf"
)
var versionNumber, operatingSystem, architecture string
func main() {
flag.Parse(true)
if *conf.Version || *conf.V {
printVersion()
return
}
if flag.NArg() == 0 {
help()
return
}
var err error
if c, ok := commands.Commands[flag.Arg(0)]; !ok {
err = commands.Query(strings.Join(flag.Args(), " "))
} else {
err = c.F(flag.Args())
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func help() {
underline := color.New(color.Underline)
green := color.New(color.FgGreen)
blue := color.New(color.FgBlue)
underline.Println("Usage:")
fmt.Print("\t$ ")
green.Println("borg \"your question\"\n")
fmt.Print("\t$ ")
green.Println("borg COMMAND\n")
fmt.Print("\n\t BORG - Terminal based search for bash snippets\n\n")
underline.Println("Commands:\n\n")
for k, v := range commands.Commands {
green.Printf("\t+ %-8s\t", k)
fmt.Println(v.Summary)
}
// TODO: Display all the possible flags
underline.Println("\nOptions:\n\n")
// TODO: Replace --help so that it displays this usage instead
blue.Printf("\t%-8s\t", "--help")
fmt.Println("Show help")
}
func printVersion() {
fmt.Printf("\tBorg version: %s (%s/%s)\n", versionNumber, operatingSystem, architecture)
}