-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag.go
36 lines (33 loc) · 840 Bytes
/
flag.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
package main
import (
"flag"
"fmt"
"os"
"strings"
"text/tabwriter"
)
var (
isGlobal bool
allowedGlobal = map[Action]struct{}{
USE: {},
EDIT: {},
DELETE: {},
}
)
func parseFlag() {
flag.Usage = func() {
sb := new(strings.Builder)
fmt.Fprintf(sb, "usage: %s [options] command\n", os.Args[0])
sb.WriteString("\nAvailable commands\n")
tw := tabwriter.NewWriter(sb, 0, 4, 1, ' ', 0)
for _, actionName := range actionString[1:] {
fmt.Fprintf(tw, " %s\t\t%s\n", actionName, commands[getAction(actionName)].Description)
}
tw.Flush()
sb.WriteString("\nAvailable options:\n")
fmt.Fprint(flag.CommandLine.Output(), sb.String())
flag.PrintDefaults()
}
flag.BoolVar(&isGlobal, "g", false, "Run the command globally (can only be used with the 'use', 'edit', and 'delete' commands).")
flag.Parse()
}