Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rustyjux committed Jun 25, 2024
1 parent 600df72 commit 8e82951
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ func NewStatusCmd(ctx *pkg.AppContext, buf *bytes.Buffer) *cobra.Command {
return nil
}

var tbl table.Table
if len(data) > 0 {
var tbl table.Table
headers := []string{"Status", "Name", "Reason", "Upstream"}
if isVerbose {
tbl = table.New("Status", "Name", "Reason", "Upstream", "Host", "EnvHost")
} else {
tbl = table.New("Status", "Name", "Reason", "Upstream")
headers = append(headers, "Host", "EnvHost")
}

cols := make([]interface{}, len(headers))
for i, header := range headers {
cols[i] = header
}
tbl = table.New(cols...)

if buf != nil {
tbl.WithWriter(buf)
}
Expand All @@ -60,11 +65,11 @@ func NewStatusCmd(ctx *pkg.AppContext, buf *bytes.Buffer) *cobra.Command {
if item.Status == "DOWN" {
statusText = pkg.ErrorStyle.Render(item.Status)
}
row := []interface{}{statusText, item.Name, item.Reason, item.Upstream}
if isVerbose {
tbl.AddRow(statusText, item.Name, item.Reason, item.Upstream, item.Host, item.EnvHost)
} else {
tbl.AddRow(statusText, item.Name, item.Reason, item.Upstream)
row = append(row, item.Host, item.EnvHost)
}
tbl.AddRow(row...)
}
tbl.Print()
} else {
Expand Down

0 comments on commit 8e82951

Please sign in to comment.