make quantity flag work with pflag package

This commit is contained in:
Daniel Smith
2015-01-14 14:48:52 -08:00
parent 30be0eeac7
commit 5767b41b28
2 changed files with 15 additions and 0 deletions

View File

@@ -386,6 +386,7 @@ type qFlag struct {
dest *Quantity
}
// Sets the value of the internal Quantity. (used by flag & pflag)
func (qf qFlag) Set(val string) error {
q, err := ParseQuantity(val)
if err != nil {
@@ -396,10 +397,16 @@ func (qf qFlag) Set(val string) error {
return nil
}
// Converts the value of the internal Quantity to a string. (used by flag & pflag)
func (qf qFlag) String() 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).
// Will panic if defaultValue is not a valid quantity.
func QuantityFlag(flagName, defaultValue, description string) *Quantity {