mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 05:43:36 -05:00
Bumps [github.com/spf13/pflag](https://github.com/spf13/pflag) from 1.0.10 to 1.1.0. - [Release notes](https://github.com/spf13/pflag/releases) - [Commits](https://github.com/spf13/pflag/compare/v1.0.10...v1.1.0) --- updated-dependencies: - dependency-name: github.com/spf13/pflag dependency-version: 1.1.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
108 lines
3.2 KiB
Go
108 lines
3.2 KiB
Go
package pflag
|
|
|
|
import (
|
|
"errors"
|
|
"strconv"
|
|
)
|
|
|
|
// optional interface to indicate boolean flags that can be
|
|
// supplied without "=value" text
|
|
type boolFlag interface {
|
|
Value
|
|
IsBoolFlag() bool
|
|
}
|
|
|
|
func isNoOptBoolValue(v Value) bool {
|
|
if bf, ok := v.(boolFlag); ok {
|
|
return bf.IsBoolFlag()
|
|
}
|
|
return false
|
|
}
|
|
|
|
// -- bool Value
|
|
type boolValue bool
|
|
|
|
func newBoolValue(val bool, p *bool) *boolValue {
|
|
*p = val
|
|
return (*boolValue)(p)
|
|
}
|
|
|
|
func (b *boolValue) Set(s string) error {
|
|
v, err := strconv.ParseBool(s)
|
|
if err != nil {
|
|
return errors.New("must be true or false")
|
|
}
|
|
*b = boolValue(v)
|
|
return nil
|
|
}
|
|
|
|
func (b *boolValue) Type() string {
|
|
return "bool"
|
|
}
|
|
|
|
func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) }
|
|
|
|
func (b *boolValue) IsBoolFlag() bool { return true }
|
|
|
|
func boolConv(sval string) (interface{}, error) {
|
|
return strconv.ParseBool(sval)
|
|
}
|
|
|
|
// GetBool return the bool value of a flag with the given name
|
|
func (f *FlagSet) GetBool(name string) (bool, error) {
|
|
val, err := f.getFlagType(name, "bool", boolConv)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return val.(bool), nil
|
|
}
|
|
|
|
// BoolVar defines a bool flag with specified name, default value, and usage string.
|
|
// The argument p points to a bool variable in which to store the value of the flag.
|
|
func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) {
|
|
f.BoolVarP(p, name, "", value, usage)
|
|
}
|
|
|
|
// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
|
|
func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
|
|
flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage)
|
|
flag.NoOptDefVal = "true"
|
|
}
|
|
|
|
// BoolVar defines a bool flag with specified name, default value, and usage string.
|
|
// The argument p points to a bool variable in which to store the value of the flag.
|
|
func BoolVar(p *bool, name string, value bool, usage string) {
|
|
BoolVarP(p, name, "", value, usage)
|
|
}
|
|
|
|
// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
|
|
func BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
|
|
flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage)
|
|
flag.NoOptDefVal = "true"
|
|
}
|
|
|
|
// Bool defines a bool flag with specified name, default value, and usage string.
|
|
// The return value is the address of a bool variable that stores the value of the flag.
|
|
func (f *FlagSet) Bool(name string, value bool, usage string) *bool {
|
|
return f.BoolP(name, "", value, usage)
|
|
}
|
|
|
|
// BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
|
|
func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool {
|
|
p := new(bool)
|
|
f.BoolVarP(p, name, shorthand, value, usage)
|
|
return p
|
|
}
|
|
|
|
// Bool defines a bool flag with specified name, default value, and usage string.
|
|
// The return value is the address of a bool variable that stores the value of the flag.
|
|
func Bool(name string, value bool, usage string) *bool {
|
|
return BoolP(name, "", value, usage)
|
|
}
|
|
|
|
// BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
|
|
func BoolP(name, shorthand string, value bool, usage string) *bool {
|
|
b := CommandLine.BoolP(name, shorthand, value, usage)
|
|
return b
|
|
}
|