~ubuntu-branches/ubuntu/utopic/golang/utopic

« back to all changes in this revision

Viewing changes to src/pkg/flag/flag.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
        After parsing, the arguments after the flag are available as the
35
35
        slice flag.Args() or individually as flag.Arg(i).
36
 
        The arguments are indexed from 0 up to flag.NArg().
 
36
        The arguments are indexed from 0 through flag.NArg()-1.
37
37
 
38
38
        Command line flag syntax:
39
39
                -flag
91
91
 
92
92
func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }
93
93
 
 
94
func (b *boolValue) IsBoolFlag() bool { return true }
 
95
 
 
96
// optional interface to indicate boolean flags that can be
 
97
// supplied without "=value" text
 
98
type boolFlag interface {
 
99
        Value
 
100
        IsBoolFlag() bool
 
101
}
 
102
 
94
103
// -- int Value
95
104
type intValue int
96
105
 
204
213
 
205
214
// Value is the interface to the dynamic value stored in a flag.
206
215
// (The default value is represented as a string.)
 
216
//
 
217
// If a Value has an IsBoolFlag() bool method returning true,
 
218
// the command-line parser makes -name equivalent to -name=true
 
219
// rather than using the next command-line argument.
207
220
type Value interface {
208
221
        String() string
209
222
        Set(string) error
704
717
                }
705
718
                return false, f.failf("flag provided but not defined: -%s", name)
706
719
        }
707
 
        if fv, ok := flag.Value.(*boolValue); ok { // special case: doesn't need an arg
 
720
        if fv, ok := flag.Value.(boolFlag); ok && fv.IsBoolFlag() { // special case: doesn't need an arg
708
721
                if has_value {
709
722
                        if err := fv.Set(value); err != nil {
710
 
                                f.failf("invalid boolean value %q for  -%s: %v", value, name, err)
 
723
                                return false, f.failf("invalid boolean value %q for  -%s: %v", value, name, err)
711
724
                        }
712
725
                } else {
713
726
                        fv.Set("true")