Skip to content

Commit

Permalink
Merge pull request bcicen#244 from stokito/fix_243
Browse files Browse the repository at this point in the history
bcicen#243 Fix bug: show ENV variables
  • Loading branch information
bcicen authored Dec 14, 2020
2 parents 537bb2a + f2c28c5 commit 0094cba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 1 addition & 3 deletions connector/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ func (cm *Docker) refresh(c *container.Container) {
c.SetMeta("ports", portsFormat(insp.NetworkSettings.Ports))
c.SetMeta("created", insp.Created.Format("Mon Jan 2 15:04:05 2006"))
c.SetMeta("health", insp.State.Health.Status)
for _, env := range insp.Config.Env {
c.SetMeta("[ENV-VAR]", env)
}
c.SetMeta("[ENV-VAR]", strings.Join(insp.Config.Env, ";"))
c.SetState(insp.State.Status)
}

Expand Down
17 changes: 10 additions & 7 deletions cwidgets/single/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package single
import (
ui "github.com/gizak/termui"
"regexp"
"strings"
)

var envPattern = regexp.MustCompile(`(?P<KEY>[^=]+)=(?P<VALUJE>.*)`)
Expand All @@ -23,14 +24,16 @@ func NewEnv() *Env {
return i
}

func (w *Env) Set(k, v string) {
match := envPattern.FindStringSubmatch(v)
key := match[1]
value := match[2]
w.data[key] = value

func (w *Env) Set(allEnvs string) {
envs := strings.Split(allEnvs, ";")
w.Rows = [][]string{}
w.Rows = append(w.Rows, mkInfoRows(key, value)...)
for _, env := range envs {
match := envPattern.FindStringSubmatch(env)
key := match[1]
value := match[2]
w.data[key] = value
w.Rows = append(w.Rows, mkInfoRows(key, value)...)
}

w.Height = len(w.Rows) + 2
}
2 changes: 1 addition & 1 deletion cwidgets/single/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (e *Single) SetWidth(w int) { e.Width = w }
func (e *Single) SetMeta(m models.Meta) {
for k, v := range m {
if k == "[ENV-VAR]" {
e.Env.Set(k, v)
e.Env.Set(v)
} else {
e.Info.Set(k, v)
}
Expand Down

0 comments on commit 0094cba

Please sign in to comment.