55 that give one-letter shorthands for flags. You can use these by appending |
55 that give one-letter shorthands for flags. You can use these by appending |
56 'P' to the name of any function that defines a flag. |
56 'P' to the name of any function that defines a flag. |
57 var ip = flag.IntP("flagname", "f", 1234, "help message") |
57 var ip = flag.IntP("flagname", "f", 1234, "help message") |
58 var flagvar bool |
58 var flagvar bool |
59 func init() { |
59 func init() { |
60 flag.BoolVarP("boolname", "b", true, "help message") |
60 flag.BoolVarP(&flagvar, "boolname", "b", true, "help message") |
61 } |
61 } |
62 flag.VarP(&flagVar, "varname", "v", 1234, "help message") |
62 flag.VarP(&flagval, "varname", "v", "help message") |
63 Shorthand letters can be used with single dashes on the command line. |
63 Shorthand letters can be used with single dashes on the command line. |
64 Boolean shorthand flags can be combined with other shorthand flags. |
64 Boolean shorthand flags can be combined with other shorthand flags. |
65 |
65 |
66 Command line flag syntax: |
66 Command line flag syntax: |
67 --flag // boolean flags only |
67 --flag // boolean flags only |
186 // (The default value is represented as a string.) |
186 // (The default value is represented as a string.) |
187 type Value interface { |
187 type Value interface { |
188 String() string |
188 String() string |
189 Set(string) error |
189 Set(string) error |
190 Type() string |
190 Type() string |
|
191 } |
|
192 |
|
193 // SliceValue is a secondary interface to all flags which hold a list |
|
194 // of values. This allows full control over the value of list flags, |
|
195 // and avoids complicated marshalling and unmarshalling to csv. |
|
196 type SliceValue interface { |
|
197 // Append adds the specified value to the end of the flag value list. |
|
198 Append(string) error |
|
199 // Replace will fully overwrite any data currently in the flag value list. |
|
200 Replace([]string) error |
|
201 // GetSlice returns the flag value list as an array of strings. |
|
202 GetSlice() []string |
191 } |
203 } |
192 |
204 |
193 // sortFlags returns the flags as a slice in lexicographical sorted order. |
205 // sortFlags returns the flags as a slice in lexicographical sorted order. |
194 func sortFlags(flags map[NormalizedName]*Flag) []*Flag { |
206 func sortFlags(flags map[NormalizedName]*Flag) []*Flag { |
195 list := make(sort.StringSlice, len(flags)) |
207 list := make(sort.StringSlice, len(flags)) |