help function

This commit is contained in:
Roy Olav Purser 2021-06-18 14:19:53 +02:00
parent ab7e9ada6f
commit 8dfd5378c0
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -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.