-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.go
31 lines (24 loc) · 981 Bytes
/
cmd.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
package main
import (
"os"
"github.com/teris-io/cli"
)
func parse() {
co := cli.NewCommand("checkout", "checkout a branch or revision").
WithShortcut("co").
WithArg(cli.NewArg("revision", "branch or revision to checkout")).
WithOption(cli.NewOption("branch", "Create branch if missing").WithChar('b').WithType(cli.TypeBool)).
WithOption(cli.NewOption("upstream", "Set upstream for the branch").WithChar('u').WithType(cli.TypeBool)).
WithAction(func(args []string, options map[string]string) int {
// do something
return 0
})
add := cli.NewCommand("add", "add a remote").WithArg(cli.NewArg("remote", "remote to add"))
rmt := cli.NewCommand("remote", "Work with git remotes").WithCommand(add)
app := cli.New("git tool").
WithOption(cli.NewOption("verbose", "Verbose execution").WithChar('v').WithType(cli.TypeBool)).
WithCommand(co).
WithCommand(rmt)
// no action attached, just print usage when executed
os.Exit(app.Run(os.Args, os.Stdout))
}