...
1 package rags_test
2
3 import (
4 "flag"
5 "os"
6
7 "edge-infra.dev/pkg/lib/cli/rags"
8 )
9
10 func ExampleRagSet_Usage() {
11
12
13 var (
14 rs = rags.New("example-flag-usage", flag.ContinueOnError)
15 _ = rs.String("foo", "", "special flag foo boy", rags.WithCategory("special"))
16 _ = rs.String("bar", "foo", "super special copy flag", rags.WithCategory("special"), rags.WithShort("b"))
17 _ = rs.Bool("reqfoo", true, "required foo", rags.WithRequired())
18 _ = rs.Bool("required2", false, "you'll need me too", rags.WithRequired())
19 _ = rs.String("shortie", "tallboi", "peep my short flag", rags.WithShort("s"))
20 _ = rs.Bool("reg", true, "just a regular ol flag type beat")
21 _ = rs.Bool("reg2", false, "another reggie")
22 )
23
24 rs.SetOutput(os.Stdout)
25 rs.Usage()
26 }
27
28 func ExampleNew_addOnCreate() {
29 var (
30 enabled bool
31 target string
32 )
33
34 rs := rags.New("example-add-flags", flag.ContinueOnError,
35 &rags.Rag{Name: "enable", Short: "e", Value: &rags.Bool{Var: &enabled}},
36 &rags.Rag{Name: "target", Required: true, Value: &rags.String{Var: &target}},
37 )
38
39 _ = rs.Bool("imperative-enable", false, "added with FlagSet drop-in replacement")
40 }
41
42 func ExampleNew_addAfterCreate() {
43 var (
44 enabled bool
45 target string
46 )
47
48 rs := rags.New("example-add-flags", flag.ContinueOnError)
49 rs.Add(
50 &rags.Rag{Name: "enable", Short: "e", Value: &rags.Bool{Var: &enabled}},
51 &rags.Rag{Name: "target", Required: true, Value: &rags.String{Var: &target}},
52 )
53
54 _ = rs.Bool("imperative-enable", false, "added FlagSet-style")
55 }
56
View as plain text