File: arg.go

package info (click to toggle)
golang-github-anacrolix-tagflag 0.0.0-20180109-2146c8d-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 132 kB
  • sloc: makefile: 2
file content (27 lines) | stat: -rw-r--r-- 558 bytes parent folder | download | duplicates (2)
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)
}