-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamples_test.go
40 lines (35 loc) · 883 Bytes
/
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
package flagtag
import (
"fmt"
"log"
"time"
)
func ExampleMustConfigureAndParse_greeter() {
// Prepare configuration
var config struct {
Greeting string `flag:"greet,Hello,The greeting."`
Name string `flag:"name,User,The user's name."`
Times int `flag:"times,1,Number of repeats."`
}
MustConfigureAndParse(&config)
// Start greeting
for i := 0; i < config.Times; i++ {
fmt.Printf("%s %s!\n", config.Greeting, config.Name)
}
}
func ExampleMustConfigureAndParse_sleep() {
// Prepare configuration
var config struct {
Sleep time.Duration `flag:"s,1s,The amount of time to sleep."`
Verbose bool `flag:"v,false,Verbose output."`
}
MustConfigureAndParse(&config)
// Start sleeping.
if config.Verbose {
log.Println("Sleeping for " + config.Sleep.String())
}
time.Sleep(config.Sleep)
if config.Verbose {
log.Println("Done.")
}
}