forked from cornfeedhobo/pflag
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
51 lines (36 loc) · 1009 Bytes
/
example_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
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zflag_test
import (
"fmt"
"github.com/zulucmd/zflag/v2"
)
func ExampleShorthandLookup() {
name := "verbose"
short := 'v'
zflag.Bool(name, false, "verbose output", zflag.OptShorthand(short))
// len(short) must be == 1
flag := zflag.ShorthandLookup(short)
fmt.Println(flag.Name)
// Output:
// verbose
}
func ExampleFlagSet_ShorthandLookup() {
name := "verbose"
short := 'v'
fs := zflag.NewFlagSet("Example", zflag.ContinueOnError)
fs.Bool(name, false, "verbose output", zflag.OptShorthand(short))
// len(short) must be == 1
flag := fs.ShorthandLookup(short)
fmt.Println(flag.Name)
// Output:
// verbose
}
func ExampleFlag_Required() {
fs := zflag.NewFlagSet("Example", zflag.ContinueOnError)
fs.Bool("required", false, "flag must be set", zflag.OptRequired())
err := fs.Parse([]string{})
fmt.Println(err)
// Output:
// required flag(s) "--required" not set
}