From 8dfd5378c087967dd66bbe3434a26251b213ba7a Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Fri, 18 Jun 2021 14:19:53 +0200 Subject: [PATCH] help function --- envconf.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/envconf.go b/envconf.go index 55a1e7d..5be7080 100644 --- a/envconf.go +++ b/envconf.go @@ -117,6 +117,29 @@ func (c *Config) Parse() { } } +func (c *Config) Help() { + max := 0 + for k, v := range c.env { + if v.dtype != TypeNone { + if len(k) > max { + max = len(k) + } + if len(v.dtype.String()) > max { + max = len(v.dtype.String()) + } + if len(v.value) > max { + max = len(v.value) + } + } + } + for k, v := range c.env { + if v.dtype != TypeNone { + format := fmt.Sprintf("Variable %%%ds|Type %%%ds|Default %%s\n", max, max) + fmt.Printf(format, k, v.dtype, v.value) + } + } +} + // Status prints out failures that occured while parsing the environment to os.Stderr. // Variables that have been defined without a default value and are // missing from the environment will be considered a failure.