MCPcopy Index your code
hub / github.com/coder/coder / listOrganizations

Method listOrganizations

cli/organizationlist.go:11–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9)
10
11func (r *RootCmd) listOrganizations() *serpent.Command {
12 formatter := cliui.NewOutputFormatter(
13 cliui.TableFormat([]codersdk.Organization{}, []string{"name", "display name", "id", "default"}),
14 cliui.JSONFormat(),
15 )
16
17 cmd := &serpent.Command{
18 Use: "list",
19 Short: "List all organizations",
20 Long: "List all organizations. Requires a role which grants ResourceOrganization: read.",
21 Aliases: []string{"ls"},
22 Middleware: serpent.Chain(
23 serpent.RequireNArgs(0),
24 ),
25 Handler: func(inv *serpent.Invocation) error {
26 client, err := r.InitClient(inv)
27 if err != nil {
28 return err
29 }
30
31 organizations, err := client.Organizations(inv.Context())
32 if err != nil {
33 return err
34 }
35
36 out, err := formatter.Format(inv.Context(), organizations)
37 if err != nil {
38 return err
39 }
40
41 if out == "" {
42 cliui.Infof(inv.Stderr, "No organizations found.")
43 return nil
44 }
45
46 _, err = fmt.Fprintln(inv.Stdout, out)
47 return err
48 },
49 }
50
51 formatter.AttachOptions(&cmd.Options)
52 return cmd
53}

Callers 1

organizationsMethod · 0.95

Calls 9

InitClientMethod · 0.95
FormatMethod · 0.95
AttachOptionsMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
InfofFunction · 0.92
OrganizationsMethod · 0.80
ContextMethod · 0.65

Tested by

no test coverage detected