Skip to content

Commit

Permalink
Merge pull request #90 from paninetworks/jb-423
Browse files Browse the repository at this point in the history
Better message when no segments were defined.
  • Loading branch information
pritesh authored Nov 25, 2016
2 parents fca85ab + f2e5e58 commit 251a44f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions romana/cmd/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"encoding/json"
"fmt"
"net/http"
"os"
"text/tabwriter"

Expand Down Expand Up @@ -241,6 +242,12 @@ func tenantShow(cmd *cli.Command, args []string) error {
tenants := []tenantData{}
err = client.Get(tenantURL+"/tenants", &data)
if err != nil {
httpErr, ok := err.(common.HttpError)
// A 404 here means that no tenants have been defined, yet. That's not
// an error.
if ok && httpErr.StatusCode == http.StatusNotFound {
fmt.Println("No tenants are currently defined")
}
return err
}

Expand All @@ -250,7 +257,14 @@ func tenantShow(cmd *cli.Command, args []string) error {
seg := []tenant.Segment{}
err = client.Get(tenantURL+"/tenants/"+t.ExternalID+"/segments", &seg)
if err != nil {
return err
httpErr, ok := err.(common.HttpError)
// A 404 just means that there are no segments defined yet.
// That's not an error. That's why we only return an error
// here if it's a non-HTTP error or the HTTP status code is
// something besides 404.
if !ok || httpErr.StatusCode != http.StatusNotFound {
return err
}
}
tenants = append(tenants, tenantData{t, seg})
}
Expand All @@ -274,8 +288,12 @@ func tenantShow(cmd *cli.Command, args []string) error {
for _, t := range tenants {
fmt.Fprintf(w, "%d \t %s \t %s \t", t.Tenant.ID,
t.Tenant.Name, t.Tenant.ExternalID)
for _, s := range t.Segments {
fmt.Fprintf(w, "%s, ", s.Name)
if len(t.Segments) > 0 {
for _, s := range t.Segments {
fmt.Fprintf(w, "%s, ", s.Name)
}
} else {
fmt.Fprintf(w, "(no segments defined)")
}
fmt.Fprintf(w, "\n")
}
Expand Down

0 comments on commit 251a44f

Please sign in to comment.