#243 Fix bug: show ENV variables

Previously only last env variable is shown
This commit is contained in:
Sergey Ponomarev 2020-12-09 23:06:14 +02:00
parent b32f90fa4a
commit f2c28c5fb0
3 changed files with 12 additions and 11 deletions

View File

@ -175,9 +175,7 @@ func (cm *Docker) refresh(c *container.Container) {
c.SetMeta("ports", portsFormat(insp.NetworkSettings.Ports)) c.SetMeta("ports", portsFormat(insp.NetworkSettings.Ports))
c.SetMeta("created", insp.Created.Format("Mon Jan 2 15:04:05 2006")) c.SetMeta("created", insp.Created.Format("Mon Jan 2 15:04:05 2006"))
c.SetMeta("health", insp.State.Health.Status) c.SetMeta("health", insp.State.Health.Status)
for _, env := range insp.Config.Env { c.SetMeta("[ENV-VAR]", strings.Join(insp.Config.Env, ";"))
c.SetMeta("[ENV-VAR]", env)
}
c.SetState(insp.State.Status) c.SetState(insp.State.Status)
} }

View File

@ -3,6 +3,7 @@ package single
import ( import (
ui "github.com/gizak/termui" ui "github.com/gizak/termui"
"regexp" "regexp"
"strings"
) )
var envPattern = regexp.MustCompile(`(?P<KEY>[^=]+)=(?P<VALUJE>.*)`) var envPattern = regexp.MustCompile(`(?P<KEY>[^=]+)=(?P<VALUJE>.*)`)
@ -23,14 +24,16 @@ func NewEnv() *Env {
return i return i
} }
func (w *Env) Set(k, v string) { func (w *Env) Set(allEnvs string) {
match := envPattern.FindStringSubmatch(v) envs := strings.Split(allEnvs, ";")
w.Rows = [][]string{}
for _, env := range envs {
match := envPattern.FindStringSubmatch(env)
key := match[1] key := match[1]
value := match[2] value := match[2]
w.data[key] = value w.data[key] = value
w.Rows = [][]string{}
w.Rows = append(w.Rows, mkInfoRows(key, value)...) w.Rows = append(w.Rows, mkInfoRows(key, value)...)
}
w.Height = len(w.Rows) + 2 w.Height = len(w.Rows) + 2
} }

View File

@ -55,7 +55,7 @@ func (e *Single) SetWidth(w int) { e.Width = w }
func (e *Single) SetMeta(m models.Meta) { func (e *Single) SetMeta(m models.Meta) {
for k, v := range m { for k, v := range m {
if k == "[ENV-VAR]" { if k == "[ENV-VAR]" {
e.Env.Set(k, v) e.Env.Set(v)
} else { } else {
e.Info.Set(k, v) e.Info.Set(k, v)
} }