-
Notifications
You must be signed in to change notification settings - Fork 42
/
deblocus.go
122 lines (111 loc) · 2.83 KB
/
deblocus.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"os"
"github.com/codegangsta/cli"
)
func setupCommands() *cli.App {
app := cli.NewApp()
app.Name = app_name
app.Usage = project_url
app.Version = versionString() + "\n " + buildInfo()
app.HideVersion = true
//app.HideHelp = true
globalOptions := []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "indicate Config path if it in nontypical path",
Destination: &context.configFile,
},
cli.IntFlag{
Name: "v",
Usage: "Verbose log level",
Destination: &context.vFlag,
},
cli.StringFlag{
Name: "logdir, ld",
Usage: "write log into the directory",
Destination: &context.logdir,
},
cli.BoolFlag{
Name: "version, V",
Usage: "show version",
Destination: &context.showVer,
},
cli.BoolFlag{
Name: "debug",
Usage: "debug",
Destination: &context.debug,
},
}
subOptions := []cli.Flag{
cli.StringFlag{
Name: "type, t",
Usage: "Specify type of key to create.",
},
cli.StringFlag{
Name: "output, o",
Usage: "Output file",
},
cli.StringFlag{
Name: "addr, a",
Usage: "Public Address",
},
}
app.Commands = []cli.Command{
{
Name: "csc",
Usage: "Create server config template",
ArgsUsage: "deblocus csc [options]",
Description: _csc_examples,
Action: context.cscCommandHandler,
Flags: subOptions[:2],
},
{
Name: "ccc",
Usage: "Create client config of specified user",
ArgsUsage: "deblocus ccc [options] <username>",
Description: _ccc_examples,
Action: context.cccCommandHandler,
Flags: append(subOptions[1:], globalOptions[0]),
},
{
Name: "keyinfo",
Usage: "Print key info from config",
ArgsUsage: "deblocus keyinfo [options]",
Description: _keyinfo_examples,
Action: context.keyInfoCommandHandler,
Flags: []cli.Flag{globalOptions[0]},
},
}
app.Flags = globalOptions
app.Before = context.initialize
app.Action = context.startCommandHandler
cli.CommandHelpTemplate = CommandHelpTemplate
return app
}
func main() {
app := setupCommands()
app.Run(os.Args)
}
// In fact, cli.Usage is description
// regard cli.ArgsUsage as usage
// regard cli.Description as examples
const CommandHelpTemplate = `COMMAND:
{{.HelpName}} - {{.Usage}}{{if .ArgsUsage}}
USAGE:
{{.ArgsUsage}}{{end}}{{if .Description}}
EXAMPLES:{{.Description}}{{end}}{{if .Flags}}
OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
const _csc_examples = `
./deblocus csc > deblocus.ini
./deblocus csc -o deblocus.ini
./deblocus csc -t [ECC-P224,256,384,521 | RSA-1024,2048,4096]`
const _ccc_examples = `
./deblocus ccc --addr=example.com:9008 user
./deblocus ccc -o file user`
const _keyinfo_examples = `
./deblocus keyinfo
./deblocus keyinfo -c someconfig.ini`