add newlines

This commit is contained in:
Roy Olav Purser 2021-06-18 15:07:31 +02:00
parent 7d9f8195b7
commit c7e42dc9c0
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -76,6 +76,7 @@ func (c *Config) DefineDefault(key string, val string, dtype DataType) {
entry.dtype = dtype entry.dtype = dtype
entry.empty = false entry.empty = false
entry.defval = val entry.defval = val
entry.hasdef = true
c.env[upper] = entry c.env[upper] = entry
} else { } else {
var entry cEntry var entry cEntry
@ -84,6 +85,7 @@ func (c *Config) DefineDefault(key string, val string, dtype DataType) {
entry.empty = false entry.empty = false
entry.value = val entry.value = val
entry.defval = val entry.defval = val
entry.hasdef = true
c.env[upper] = entry c.env[upper] = entry
} }
} }
@ -123,6 +125,8 @@ func (c *Config) Parse() {
func (c *Config) help() { func (c *Config) help() {
max := make([]int, 2, 2) max := make([]int, 2, 2)
preq := false
pdef := false
for k, v := range c.env { for k, v := range c.env {
if v.dtype != TypeNone { if v.dtype != TypeNone {
if len(k) > max[0] { if len(k) > max[0] {
@ -131,23 +135,32 @@ func (c *Config) help() {
if len(v.dtype.String()) > max[1] { if len(v.dtype.String()) > max[1] {
max[1] = len(v.dtype.String()) max[1] = len(v.dtype.String())
} }
}
}
fmt.Println()
for k, v := range c.env {
if v.dtype != TypeNone {
if v.hasdef { if v.hasdef {
format := fmt.Sprintf("Variable %%-%ds| Type %%-%ds| Default %%s\n", max[0]+3, max[1]+3) pdef = true
fmt.Printf(format, k, v.dtype, v.defval) } else {
preq = true
} }
} }
} }
fmt.Println() if pdef {
for k, v := range c.env { fmt.Println()
if v.dtype != TypeNone { for k, v := range c.env {
if !v.hasdef { if v.dtype != TypeNone {
format := fmt.Sprintf("Variable %%-%ds| Type %%-%ds| Required", max[0]+3, max[1]+3) if v.hasdef {
fmt.Printf(format, k, v.dtype) 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)
}
} }
} }
} }