-
Notifications
You must be signed in to change notification settings - Fork 16
/
examples_test.go
73 lines (58 loc) · 1.35 KB
/
examples_test.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
package climax_test
import (
"fmt"
"github.com/tucnak/climax"
"strings"
)
func Example_application() {
demo := climax.New("demo")
demo.Brief = "Demo is a funky demonstation of Climax capabilities."
demo.Version = "stable"
joinCmd := climax.Command{
Name: "join",
Brief: "merges the strings given",
Usage: `[-s=] "a few" distinct strings`,
Help: `Lorem ipsum dolor sit amet amet sit todor...`,
Flags: []climax.Flag{
{
Name: "separator",
Short: "s",
Usage: `--separator="."`,
Help: `Put some separating string between all the strings given.`,
Variable: true,
},
},
Examples: []climax.Example{
{
Usecase: `-s . "google" "com"`,
Description: `Results in "google.com"`,
},
},
Handle: func(ctx climax.Context) int {
var separator string
if sep, ok := ctx.Get("separator"); ok {
separator = sep
}
fmt.Println(strings.Join(ctx.Args, separator))
return 0
},
}
demo.AddCommand(joinCmd)
demo.Run()
}
// Handler accepts a climax.Context object and returns an exitcode integer.
func Example_handler(ctx climax.Context) int {
if len(ctx.Args) < 2 {
ctx.Log("not enough arguments")
// with os.Exit(1)
return 1
}
if name, ok := ctx.Get("name"); ok {
// argument `name` parsed
fmt.Println(name)
} else {
ctx.Log("name not specified")
return 1
}
return 0
}