summaryrefslogtreecommitdiff
path: root/pkg/mflag/example/example.go
blob: ed940e8d70bcf7aa681cb410adab9ef5dc4e1ead (plain)
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
package main

import (
	"fmt"
	flag "github.com/dotcloud/docker/pkg/mflag"
)

var (
	i        int
	str      string
	b, b2, h bool
)

func init() {
	flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp")
	flag.BoolVar(&b, []string{"b"}, false, "a simple bool")
	flag.BoolVar(&b2, []string{"#-bool"}, false, "a simple bool")
	flag.IntVar(&i, []string{"-integer", "-number"}, -1, "a simple integer")
	flag.StringVar(&str, []string{"s", "#hidden", "-string"}, "", "a simple string") //-s -hidden and --string will work, but -hidden won't be in the usage
	flag.BoolVar(&h, []string{"h", "#help", "-help"}, false, "display the help")
	flag.Parse()
}
func main() {
	if h {
		flag.PrintDefaults()
	}
	fmt.Printf("s/#hidden/-string: %s\n", str)
	fmt.Printf("b: %b\n", b)
	fmt.Printf("-bool: %b\n", b2)
	fmt.Printf("s/#hidden/-string(via lookup): %s\n", flag.Lookup("s").Value.String())
	fmt.Printf("ARGS: %v\n", flag.Args())
}