|
|
@ -1,11 +1,55 @@
|
|
|
|
package cli
|
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"flag"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// boolValue needs to implement the boolFlag internal interface in flag
|
|
|
|
|
|
|
|
// to be able to capture bool fields and values
|
|
|
|
|
|
|
|
// type boolFlag interface {
|
|
|
|
|
|
|
|
// Value
|
|
|
|
|
|
|
|
// IsBoolFlag() bool
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
type boolValue struct {
|
|
|
|
|
|
|
|
destination *bool
|
|
|
|
|
|
|
|
count *int
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func newBoolValue(val bool, p *bool, count *int) *boolValue {
|
|
|
|
|
|
|
|
*p = val
|
|
|
|
|
|
|
|
return &boolValue{
|
|
|
|
|
|
|
|
destination: p,
|
|
|
|
|
|
|
|
count: count,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (b *boolValue) Set(s string) error {
|
|
|
|
|
|
|
|
v, err := strconv.ParseBool(s)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
err = errors.New("parse error")
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*b.destination = v
|
|
|
|
|
|
|
|
if b.count != nil {
|
|
|
|
|
|
|
|
*b.count = *b.count + 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (b *boolValue) Get() interface{} { return *b.destination }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (b *boolValue) String() string {
|
|
|
|
|
|
|
|
if b.destination != nil {
|
|
|
|
|
|
|
|
return strconv.FormatBool(*b.destination)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return strconv.FormatBool(false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (b *boolValue) IsBoolFlag() bool { return true }
|
|
|
|
|
|
|
|
|
|
|
|
// TakesValue returns true of the flag takes a value, otherwise false
|
|
|
|
// TakesValue returns true of the flag takes a value, otherwise false
|
|
|
|
func (f *BoolFlag) TakesValue() bool {
|
|
|
|
func (f *BoolFlag) TakesValue() bool {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
@ -61,11 +105,14 @@ func (f *BoolFlag) Apply(set *flag.FlagSet) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, name := range f.Names() {
|
|
|
|
for _, name := range f.Names() {
|
|
|
|
|
|
|
|
var value flag.Value
|
|
|
|
if f.Destination != nil {
|
|
|
|
if f.Destination != nil {
|
|
|
|
set.BoolVar(f.Destination, name, f.Value, f.Usage)
|
|
|
|
value = newBoolValue(f.Value, f.Destination, f.Count)
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
|
|
|
|
t := new(bool)
|
|
|
|
|
|
|
|
value = newBoolValue(f.Value, t, f.Count)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set.Bool(name, f.Value, f.Usage)
|
|
|
|
set.Var(value, name, f.Usage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|