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.