1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
package tagflag
import (
"fmt"
"reflect"
)
type arg struct {
arity arity
name string
help string
value reflect.Value
}
func (me arg) hasZeroValue() bool {
return reflect.DeepEqual(
reflect.Zero(me.value.Type()).Interface(),
me.value.Interface())
}
func (me arg) marshal(s string, explicitValue bool) error {
m := valueMarshaler(me.value)
if !explicitValue && m.RequiresExplicitValue() {
return userError{fmt.Sprintf("explicit value required (%s%s=VALUE)", flagPrefix, me.name)}
}
return valueMarshaler(me.value).Marshal(me.value, s)
}
|