From c7e42dc9c0b37b9099cdfc4b88eb762311e2ec87 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Fri, 18 Jun 2021 15:07:31 +0200 Subject: [PATCH] add newlines --- envconf.go | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/envconf.go b/envconf.go index 09e97b8..0dd7242 100644 --- a/envconf.go +++ b/envconf.go @@ -76,6 +76,7 @@ func (c *Config) DefineDefault(key string, val string, dtype DataType) { entry.dtype = dtype entry.empty = false entry.defval = val + entry.hasdef = true c.env[upper] = entry } else { var entry cEntry @@ -84,6 +85,7 @@ func (c *Config) DefineDefault(key string, val string, dtype DataType) { entry.empty = false entry.value = val entry.defval = val + entry.hasdef = true c.env[upper] = entry } } @@ -123,6 +125,8 @@ func (c *Config) Parse() { func (c *Config) help() { max := make([]int, 2, 2) + preq := false + pdef := false for k, v := range c.env { if v.dtype != TypeNone { if len(k) > max[0] { @@ -131,23 +135,32 @@ func (c *Config) help() { if len(v.dtype.String()) > max[1] { max[1] = len(v.dtype.String()) } - } - } - fmt.Println() - for k, v := range c.env { - if v.dtype != TypeNone { if v.hasdef { - format := fmt.Sprintf("Variable %%-%ds| Type %%-%ds| Default %%s\n", max[0]+3, max[1]+3) - fmt.Printf(format, k, v.dtype, v.defval) + pdef = true + } else { + preq = true } } } - fmt.Println() - for k, v := range c.env { - if v.dtype != TypeNone { - if !v.hasdef { - format := fmt.Sprintf("Variable %%-%ds| Type %%-%ds| Required", max[0]+3, max[1]+3) - fmt.Printf(format, k, v.dtype) + if pdef { + fmt.Println() + for k, v := range c.env { + if v.dtype != TypeNone { + if v.hasdef { + format := fmt.Sprintf("Variable %%-%ds| Type %%-%ds| Default %%s\n", max[0]+3, max[1]+3) + fmt.Printf(format, k, v.dtype, v.defval) + } + } + } + } + if preq { + fmt.Println() + for k, v := range c.env { + if v.dtype != TypeNone { + if !v.hasdef { + format := fmt.Sprintf("Variable %%-%ds| Type %%-%ds| Required\n", max[0]+3, max[1]+3) + fmt.Printf(format, k, v.dtype) + } } } }