Skip to content

Commit

Permalink
More cleanup and an early error bail optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gergely Brautigam committed Sep 25, 2019
1 parent 50e7d0c commit f09fc36
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/cluster/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (JSONFormatter) Format(w io.Writer, machines []*Machine) error {
}

// FormatSingle is a json formatter for a single machine.
func (js JSONFormatter) FormatSingle(w io.Writer, m *Machine) error {
func (JSONFormatter) FormatSingle(w io.Writer, m *Machine) error {
status, err := json.MarshalIndent(m.Status(), "", " ")
if err != nil {
return err
Expand All @@ -82,7 +82,7 @@ func (js JSONFormatter) FormatSingle(w io.Writer, m *Machine) error {
return err
}

// contains writeColumns error value to clean-up some error handling in the code
// writer contains writeColumns' error value to clean-up some error handling
type writer struct {
err error
}
Expand All @@ -107,6 +107,10 @@ func (TableFormatter) Format(w io.Writer, machines []*Machine) error {

table := tabwriter.NewWriter(w, 0, 0, padding, ' ', 0)
wr.writeColumns(table, []string{"NAME", "HOSTNAME", "PORTS", "IP", "IMAGE", "CMD", "STATE", "BACKEND"})
// we bail early here if there was an error so we don't process the below loop
if wr.err != nil {
return wr.err
}
for _, s := range statuses {
var ports []string
for k, v := range s.Ports {
Expand Down

0 comments on commit f09fc36

Please sign in to comment.