Source file
src/flag/example_textvar_test.go
1
2
3
4
5 package flag_test
6
7 import (
8 "flag"
9 "fmt"
10 "net"
11 "os"
12 )
13
14 func ExampleTextVar() {
15 fs := flag.NewFlagSet("ExampleTextVar", flag.ContinueOnError)
16 fs.SetOutput(os.Stdout)
17 var ip net.IP
18 fs.TextVar(&ip, "ip", net.IPv4(192, 168, 0, 100), "`IP address` to parse")
19 fs.Parse([]string{"-ip", "127.0.0.1"})
20 fmt.Printf("{ip: %v}\n\n", ip)
21
22
23 ip = nil
24 fs.Parse([]string{"-ip", "256.0.0.1"})
25 fmt.Printf("{ip: %v}\n\n", ip)
26
27
28
29
30
31
32
33
34
35 }
36
View as plain text