From 3f67be49b4be64ef8a5ffe98d3bd0c85295948bf Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Tue, 4 May 2021 10:28:45 +0200 Subject: [PATCH] Respec envconfig tag within usage --- usage.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/usage.go b/usage.go index aebadb0..8c60566 100644 --- a/usage.go +++ b/usage.go @@ -125,7 +125,13 @@ func Usagef(prefix string, spec interface{}, out io.Writer, format string) error // Specify the default usage template functions functions := template.FuncMap{ - "usage_key": func(v varInfo) string { return v.Key }, + "usage_key": func(v varInfo) string { + val := v.Tags.Get("envconfig") + if val != "" { + return strings.ToUpper(val) + } + return v.Key + }, "usage_description": func(v varInfo) string { return v.Tags.Get("desc") }, "usage_type": func(v varInfo) string { return toTypeDescription(v.Field.Type()) }, "usage_default": func(v varInfo) string { return v.Tags.Get("default") },