| 57 | } |
| 58 | |
| 59 | func listRun(opts *ListOptions) error { |
| 60 | httpClient, err := opts.HttpClient() |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | cfg, err := opts.Config() |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | host, _ := cfg.Authentication().DefaultHost() |
| 71 | |
| 72 | listResult, err := listOrgs(httpClient, host, opts.Limit) |
| 73 | if err != nil { |
| 74 | return err |
| 75 | } |
| 76 | |
| 77 | if err := opts.IO.StartPager(); err != nil { |
| 78 | fmt.Fprintf(opts.IO.ErrOut, "error starting pager: %v\n", err) |
| 79 | } |
| 80 | defer opts.IO.StopPager() |
| 81 | |
| 82 | if opts.IO.IsStdoutTTY() { |
| 83 | header := listHeader(listResult.User, len(listResult.Organizations), listResult.TotalCount) |
| 84 | fmt.Fprintf(opts.IO.Out, "\n%s\n\n", header) |
| 85 | } |
| 86 | |
| 87 | for _, org := range listResult.Organizations { |
| 88 | fmt.Fprintln(opts.IO.Out, org.Login) |
| 89 | } |
| 90 | |
| 91 | return nil |
| 92 | } |
| 93 | |
| 94 | func listHeader(user string, resultCount, totalCount int) string { |
| 95 | if totalCount == 0 { |