-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
43 lines (35 loc) · 941 Bytes
/
main.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
//go:build ignore
// inheritable arguments
package main
import (
"fmt"
"os"
"github.com/hellflame/argparse"
)
func main() {
parser := argparse.NewParser("", "", nil)
verbose := parser.Flag("v", "", &argparse.Option{Inheritable: true,
Help: "show verbose info"})
local := parser.AddCommand("local", "", nil)
service := parser.AddCommand("service", "", nil)
user := local.String("u", "user", nil)
pwd := local.String("p", "password", nil)
addr := service.String("", "address", nil)
port := service.Int("", "port", nil)
version := service.Int("v", "version", &argparse.Option{Help: "version choice"})
if e := parser.Parse(nil); e != nil {
switch e.(type) {
case argparse.BreakAfterHelp:
os.Exit(1)
default:
fmt.Println(e.Error())
}
return
}
if local.Invoked {
fmt.Println("local run", *verbose, *user, *pwd)
}
if service.Invoked {
fmt.Println("service run", *verbose, *addr, *port, *version)
}
}