@@ -27,23 +27,32 @@ unaffected.
2727Define flags using flag.String(), Bool(), Int(), etc.
2828
2929This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
30+
3031 var ip = flag.Int("flagname", 1234, "help message for flagname")
32+
3133If you like, you can bind the flag to a variable using the Var() functions.
34+
3235 var flagvar int
3336 func init() {
3437 flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
3538 }
39+
3640Or you can create custom flags that satisfy the Value interface (with
3741pointer receivers) and couple them to flag parsing by
42+
3843 flag.Var(&flagVal, "name", "help message for flagname")
44+
3945For such flags, the default value is just the initial value of the variable.
4046
4147After all flags are defined, call
48+
4249 flag.Parse()
50+
4351to parse the command line into the defined flags.
4452
4553Flags may then be used directly. If you're using the flags themselves,
4654they are all pointers; if you bind to variables, they're values.
55+
4756 fmt.Println("ip has value ", *ip)
4857 fmt.Println("flagvar has value ", flagvar)
4958
@@ -54,22 +63,26 @@ The arguments are indexed from 0 through flag.NArg()-1.
5463The pflag package also defines some new functions that are not in flag,
5564that give one-letter shorthands for flags. You can use these by appending
5665'P' to the name of any function that defines a flag.
66+
5767 var ip = flag.IntP("flagname", "f", 1234, "help message")
5868 var flagvar bool
5969 func init() {
6070 flag.BoolVarP(&flagvar, "boolname", "b", true, "help message")
6171 }
6272 flag.VarP(&flagval, "varname", "v", "help message")
73+
6374Shorthand letters can be used with single dashes on the command line.
6475Boolean shorthand flags can be combined with other shorthand flags.
6576
6677Command line flag syntax:
78+
6779 --flag // boolean flags only
6880 --flag=x
6981
7082Unlike the flag package, a single dash before an option means something
7183different than a double dash. Single dashes signify a series of shorthand
7284letters for flags. All but the last shorthand letter must be boolean flags.
85+
7386 // boolean flags
7487 -f
7588 -abc
@@ -551,7 +564,7 @@ func (f *Flag) defaultIsZeroValue() bool {
551564 case * intSliceValue , * stringSliceValue , * stringArrayValue :
552565 return f .DefValue == "[]"
553566 default :
554- switch f .Value . String () {
567+ switch f .DefValue {
555568 case "false" :
556569 return true
557570 case "<nil>" :
@@ -934,9 +947,9 @@ func (f *FlagSet) usage() {
934947 }
935948}
936949
937- //--unknown (args will be empty)
938- //--unknown --next-flag ... (args will be --next-flag ...)
939- //--unknown arg ... (args will be arg ...)
950+ // --unknown (args will be empty)
951+ // --unknown --next-flag ... (args will be --next-flag ...)
952+ // --unknown arg ... (args will be arg ...)
940953func stripUnknownFlagValue (args []string ) []string {
941954 if len (args ) == 0 {
942955 //--unknown
0 commit comments