mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #3482 from lavalamp/fix
make quantity flag work with pflag package
This commit is contained in:
commit
b0d9ad70de
@ -386,6 +386,7 @@ type qFlag struct {
|
|||||||
dest *Quantity
|
dest *Quantity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets the value of the internal Quantity. (used by flag & pflag)
|
||||||
func (qf qFlag) Set(val string) error {
|
func (qf qFlag) Set(val string) error {
|
||||||
q, err := ParseQuantity(val)
|
q, err := ParseQuantity(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -396,10 +397,16 @@ func (qf qFlag) Set(val string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Converts the value of the internal Quantity to a string. (used by flag & pflag)
|
||||||
func (qf qFlag) String() string {
|
func (qf qFlag) String() string {
|
||||||
return qf.dest.String()
|
return qf.dest.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// States the type of flag this is (Quantity). (used by pflag)
|
||||||
|
func (qf qFlag) Type() string {
|
||||||
|
return "quantity"
|
||||||
|
}
|
||||||
|
|
||||||
// QuantityFlag is a helper that makes a quantity flag (using standard flag package).
|
// QuantityFlag is a helper that makes a quantity flag (using standard flag package).
|
||||||
// Will panic if defaultValue is not a valid quantity.
|
// Will panic if defaultValue is not a valid quantity.
|
||||||
func QuantityFlag(flagName, defaultValue, description string) *Quantity {
|
func QuantityFlag(flagName, defaultValue, description string) *Quantity {
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
fuzz "github.com/google/gofuzz"
|
fuzz "github.com/google/gofuzz"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
"speter.net/go/exp/math/dec/inf"
|
"speter.net/go/exp/math/dec/inf"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -487,3 +488,10 @@ func TestQFlagSet(t *testing.T) {
|
|||||||
t.Errorf("Unexpected result %v != %v", e, a)
|
t.Errorf("Unexpected result %v != %v", e, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestQFlagIsPFlag(t *testing.T) {
|
||||||
|
var pfv pflag.Value = qFlag{}
|
||||||
|
if e, a := "quantity", pfv.Type(); e != a {
|
||||||
|
t.Errorf("Unexpected result %v != %v", e, a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user