From cf1331e3cdea1df871aa42bc1d39690cb3d9df05 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Fri, 18 Jun 2021 14:29:18 +0200 Subject: [PATCH] align help --- envconf.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/envconf.go b/envconf.go index 5be7080..a6d611e 100644 --- a/envconf.go +++ b/envconf.go @@ -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) } }