1 // Do not edit. Bootstrap copy of /usr/local/google/buildbot/src/android/build-tools/out/obj/go/src/cmd/internal/obj/flag.go 2 3 //line /usr/local/google/buildbot/src/android/build-tools/out/obj/go/src/cmd/internal/obj/flag.go:1 4 // Copyright 2015 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 package obj 9 10 import ( 11 "flag" 12 "fmt" 13 "os" 14 "strconv" 15 ) 16 17 func Flagfn2(string, string, func(string, string)) { panic("flag") } 18 19 func Flagcount(name, usage string, val *int) { 20 flag.Var((*count)(val), name, usage) 21 } 22 23 func Flagint32(name, usage string, val *int32) { 24 flag.Var((*int32Value)(val), name, usage) 25 } 26 27 func Flagint64(name, usage string, val *int64) { 28 flag.Int64Var(val, name, *val, usage) 29 } 30 31 func Flagstr(name, usage string, val *string) { 32 flag.StringVar(val, name, *val, usage) 33 } 34 35 func Flagfn0(name, usage string, f func()) { 36 flag.Var(fn0(f), name, usage) 37 } 38 39 func Flagfn1(name, usage string, f func(string)) { 40 flag.Var(fn1(f), name, usage) 41 } 42 43 func Flagprint(fd int) { 44 if fd == 1 { 45 flag.CommandLine.SetOutput(os.Stdout) 46 } 47 flag.PrintDefaults() 48 } 49 50 func Flagparse(usage func()) { 51 flag.Usage = usage 52 flag.Parse() 53 } 54 55 // count is a flag.Value that is like a flag.Bool and a flag.Int. 56 // If used as -name, it increments the count, but -name=x sets the count. 57 // Used for verbose flag -v. 58 type count int 59 60 func (c *count) String() string { 61 return fmt.Sprint(int(*c)) 62 } 63 64 func (c *count) Set(s string) error { 65 switch s { 66 case "true": 67 *c++ 68 case "false": 69 *c = 0 70 default: 71 n, err := strconv.Atoi(s) 72 if err != nil { 73 return fmt.Errorf("invalid count %q", s) 74 } 75 *c = count(n) 76 } 77 return nil 78 } 79 80 func (c *count) IsBoolFlag() bool { 81 return true 82 } 83 84 type int32Value int32 85 86 func newIntValue(val int32, p *int32) *int32Value { 87 *p = val 88 return (*int32Value)(p) 89 } 90 91 func (i *int32Value) Set(s string) error { 92 v, err := strconv.ParseInt(s, 0, 64) 93 *i = int32Value(v) 94 return err 95 } 96 97 func (i *int32Value) Get() interface{} { return int32(*i) } 98 99 func (i *int32Value) String() string { return fmt.Sprint(*i) } 100 101 type fn0 func() 102 103 func (f fn0) Set(s string) error { 104 f() 105 return nil 106 } 107 108 func (f fn0) Get() interface{} { return nil } 109 110 func (f fn0) String() string { return "" } 111 112 func (f fn0) IsBoolFlag() bool { 113 return true 114 } 115 116 type fn1 func(string) 117 118 func (f fn1) Set(s string) error { 119 f(s) 120 return nil 121 } 122 123 func (f fn1) String() string { return "" } 124