align help

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

View File

@ -118,23 +118,20 @@ func (c *Config) Parse() {
}
func (c *Config) Help() {
max := 0
max := make([]int, 2, 2)
for k, v := range c.env {
if v.dtype != TypeNone {
if len(k) > max {
max = len(k)
if len(k) > max[0] {
max[0] = len(k)
}
if len(v.dtype.String()) > max {
max = len(v.dtype.String())
}
if len(v.value) > max {
max = len(v.value)
if len(v.dtype.String()) > max[1] {
max[1] = len(v.dtype.String())
}
}
}
for k, v := range c.env {
if v.dtype != TypeNone {
format := fmt.Sprintf("Variable %%%ds|Type %%%ds|Default %%s\n", max, max)
format := fmt.Sprintf("Variable %%-%ds| Type %%-%ds| Default %%s\n", max[0]+3, max[1]+3)
fmt.Printf(format, k, v.dtype, v.value)
}
}