-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimple.go
50 lines (43 loc) · 906 Bytes
/
simple.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
// A simple app
package main
import (
"flag"
"fmt"
"strings"
"github.com/yieldbot/gocli"
)
var (
cli gocli.Cli
usageFlag bool
versionFlag bool
)
func init() {
// Init flags
flag.BoolVar(&usageFlag, "h", false, "Display usage")
flag.BoolVar(&usageFlag, "help", false, "Display usage")
flag.BoolVar(&versionFlag, "version", false, "Display version information")
flag.BoolVar(&versionFlag, "v", false, "Display version information")
}
func main() {
// Init cli
cli = gocli.Cli{
Name: "simple",
Version: "1.0.0",
Description: "A simple app",
Commands: map[string]string{
"echo": "Print the given arguments",
},
}
cli.Init()
// Run commands
if cli.SubCommand == "echo" {
// Echo command
fmt.Println(strings.Join(cli.SubCommandArgs, " "))
} else if versionFlag {
// Version
cli.PrintVersion(true)
} else {
// Default
cli.PrintUsage()
}
}