From 904e03926794663089b73d52a02def065d819200 Mon Sep 17 00:00:00 2001 From: Andrew Morozko Date: Fri, 29 Nov 2019 22:33:16 +0300 Subject: Added the "dataname" tag --- parse.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'parse.go') diff --git a/parse.go b/parse.go index bc156df..3e1d719 100644 --- a/parse.go +++ b/parse.go @@ -56,6 +56,7 @@ type spec struct { env string boolean bool defaultVal string // default value for this option + dataname string // name of the data in help } // command represents a named subcommand, or the top-level command @@ -305,6 +306,8 @@ func cmdFromStruct(name string, dest path, t reflect.Type) (*command, error) { spec.required = true case key == "positional": spec.positional = true + case key == "dataname": + spec.dataname = value case key == "separate": spec.separate = true case key == "help": // deprecated @@ -342,6 +345,10 @@ func cmdFromStruct(name string, dest path, t reflect.Type) (*command, error) { } } + if spec.dataname == "" { + spec.dataname = strings.ToUpper(spec.long) + } + // Check whether this field is supported. It's good to do this here rather than // wait until ParseValue because it means that a program with invalid argument // fields will always fail regardless of whether the arguments it received -- cgit v1.2.3