-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (33 loc) · 1.1 KB
/
Copy pathmain.go
File metadata and controls
39 lines (33 loc) · 1.1 KB
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
//go:build ignore
// this is show case for using color in argparse
//
// demo for ColorSchema
package main
import (
"fmt"
"github.com/hellflame/argparse"
)
func main() {
parser := argparse.NewParser("basic", "this is a basic program", &argparse.ParserConfig{
WithColor: true,
WithHint: true,
EpiLog: "more info please visit https://github.com/hellflame/argparse",
})
sub := parser.AddCommand("run", "run your program", nil)
parser.AddCommand("test", "test for your program", nil)
sub.Flag("d", "dir", &argparse.Option{Help: "give me a directory"})
parser.String("n", "name", &argparse.Option{Default: "flame", Help: "your name"})
parser.Ints("t", "times", &argparse.Option{HintInfo: "run times", Group: "base", Help: "how many times"})
parser.Float("s", "size", &argparse.Option{Help: "give me a size", Group: "base", Required: true})
parser.String("u", "url", &argparse.Option{Positional: true, Help: "target url"})
parser.String("l", "", nil)
if e := parser.Parse(nil); e != nil {
switch e {
case argparse.BreakAfterHelpError:
return
default:
fmt.Println(e.Error())
}
return
}
}