Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libgo / go / flag / flag.go
index bbabd88..85dd8c3 100644 (file)
@@ -91,6 +91,15 @@ func (b *boolValue) Set(s string) error {
 
 func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }
 
+func (b *boolValue) IsBoolFlag() bool { return true }
+
+// optional interface to indicate boolean flags that can be
+// supplied without "=value" text
+type boolFlag interface {
+       Value
+       IsBoolFlag() bool
+}
+
 // -- int Value
 type intValue int
 
@@ -204,6 +213,10 @@ func (d *durationValue) String() string { return (*time.Duration)(d).String() }
 
 // Value is the interface to the dynamic value stored in a flag.
 // (The default value is represented as a string.)
+//
+// If a Value has an IsBoolFlag() bool method returning true,
+// the command-line parser makes -name equivalent to -name=true
+// rather than using the next command-line argument.
 type Value interface {
        String() string
        Set(string) error
@@ -704,7 +717,7 @@ func (f *FlagSet) parseOne() (bool, error) {
                }
                return false, f.failf("flag provided but not defined: -%s", name)
        }
-       if fv, ok := flag.Value.(*boolValue); ok { // special case: doesn't need an arg
+       if fv, ok := flag.Value.(boolFlag); ok && fv.IsBoolFlag() { // special case: doesn't need an arg
                if has_value {
                        if err := fv.Set(value); err != nil {
                                return false, f.failf("invalid boolean value %q for  -%s: %v", value, name, err)