-
Notifications
You must be signed in to change notification settings - Fork 11
/
urfave-cli5.go
executable file
·121 lines (110 loc) · 2.84 KB
/
urfave-cli5.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
// urfave-cli example #5
// Showing subcommand categories and using cli.Context passed to Action func.
// This time we are using the same function for Action of all sub commands
// and then grabbing the subcommand in the function.
package main
import (
"fmt"
"os"
"github.com/urfave/cli"
)
var cmds []cli.Command
func init() {
cmds = []cli.Command{
{
// Name
Name: "hack",
Aliases: []string{"haxorx", "pwn"},
Usage: "hack target",
// Same function for all actions
Action: act,
Category: "Hacking",
},
{
Name: "crack",
Aliases: []string{"c"},
Usage: "crack target",
Action: act,
Category: "Hacking",
},
{
Name: "scan",
Aliases: []string{"s"},
Usage: "scan target",
Action: act,
Category: "Recon",
},
{
Name: "probe",
Aliases: []string{"p"},
Usage: "probe target",
Action: act,
Category: "Recon",
},
}
}
func main() {
app := cli.NewApp()
app.Commands = cmds
app.Action = noArgs
app.Usage = "app to Hack the Planet!"
app.HideVersion = true
app.Run(os.Args)
}
// noArgs will run if no arguments/flags are provided
func noArgs(c *cli.Context) error {
// Print app usage
cli.ShowAppHelp(c)
return nil
}
// act will detect the subcommand from c and print the appropriate message
// or subcommand help if applicable.
func act(c *cli.Context) error {
if c.Args().Present() {
t := c.Args().First()
// c.Command.Name has command name
// c.Command has a lot more info
// https://godoc.org/github.com/dkolbly/cli#Command
// Knowing the subcommand we can call different functions here.
cmdName := c.Command.Name
fmt.Printf("%sing %s", cmdName, t)
return nil
}
cli.ShowSubcommandHelp(c)
return nil
}
// No arguments
// $go run urfave-cli5.go
// NAME:
// urfave-cli5.exe - app to Hack the Planet!
// USAGE:
// urfave-cli5.exe [global options] command [command options] [arguments...]
// COMMANDS:
// help, h Shows a list of commands or help for one command
// Hacking:
// hack, haxorx, pwn hack target
// crack, c crack target
// Recon:
// scan, s scan target
// probe, p probe target
// GLOBAL OPTIONS:
// --help, -h show help
// No targets
// $ go run urfave-cli5.go hack
// NAME:
// urfave-cli5.exe hack - hack target
// USAGE:
// urfave-cli5.exe hack [arguments...]
// CATEGORY:
// Hacking
// Hack the target
// $ go run urfave-cli5.go hack 127.0.0.1:1234
// hacking 127.0.0.1:1234
// $ go run urfave-cli5.go crack 127.0.0.1:1234
// cracking 127.0.0.1:1234
// Just adding -ing to the end does not work all the time
// $ go run urfave-cli5.go probe 127.0.0.1:1234
// probeing 127.0.0.1:1234
// Ditto
// $ go run urfave-cli5.go scan 127.0.0.1:1234
// scaning 127.0.0.1:1234