diff options
| author | Alex Flint <[email protected]> | 2018-04-15 18:34:32 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-04-15 18:34:32 -0700 |
| commit | b1eda2c7b64c118d56472c1944054bf9235d6c48 (patch) | |
| tree | fbcf34b3dbf7c874ed261ed390c82c6fc933479f /README.md | |
| parent | 0cc8e30fd64c8c71d094be299ad424da93ef9aed (diff) | |
| parent | 51337ded775c91dc26574d7d2dc2e493cf416138 (diff) | |
Merge pull request #62 from mwlazlo-tls/master
Custom parsers implementing encoding.TextMarshaler() can have default…
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -265,15 +265,33 @@ func (n *NameDotName) UnmarshalText(b []byte) error { return nil } +// optional: implement in case you want to display a default value in the usage string +func (n *NameDotName) MarshalText() (text []byte, err error) { + text = []byte(fmt.Sprintf("%s.%s", n.Head, n.Tail)) + return +} + func main() { var args struct { Name *NameDotName } + // set default + args.Name = &NameDotName{"file", "txt"} arg.MustParse(&args) fmt.Printf("%#v\n", args.Name) } ``` ```shell +$ ./example --help +Usage: test [--name NAME] + +Options: + --name NAME [default: file.txt] + --help, -h display this help and exit + +$ ./example +&main.NameDotName{Head:"file", Tail:"txt"} + $ ./example --name=foo.bar &main.NameDotName{Head:"foo", Tail:"bar"} |
