Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
list: clean up output format, sort by profile name
Browse files Browse the repository at this point in the history
  • Loading branch information
logikal committed Jan 18, 2019
1 parent 4ad8b0b commit a8e11be
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"sort"
"text/tabwriter"

analytics "github.com/segmentio/analytics-go"
Expand Down Expand Up @@ -32,11 +33,20 @@ func listRun(cmd *cobra.Command, args []string) error {
return err
}

// Let's sort this list of profiles so we can have some more deterministic output:
var profileNames []string

for profile := range profiles {
profileNames = append(profileNames, profile)
}

sort.Strings(profileNames)

w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 2, '\t', 0)
fmt.Fprintln(w, "profile\tarn\tsource_role\t")
fmt.Fprintln(w, "---\t---\t---\t")
for profile, v := range profiles {
fmt.Fprintln(w, "PROFILE\tARN\tSOURCE_ROLE\t")
for _, profile := range profileNames {
v := profiles[profile]
if role, exist := v["role_arn"]; exist {
fmt.Fprintf(w, "%s\t%s\t%s\n", profile, role, v["source_profile"])
}
Expand Down

0 comments on commit a8e11be

Please sign in to comment.