Skip to content

Commit d4d20af

Browse files
committed
add only-id option
1 parent b7c8c44 commit d4d20af

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

cli/organization.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,38 @@ func (r *RootCmd) currentOrganization() *clibase.Cmd {
4141
cliui.TableFormat([]codersdk.Organization{}, []string{"id", "name", "default"}),
4242
cliui.JSONFormat(),
4343
)
44+
onlyID = false
4445
)
4546
cmd := &clibase.Cmd{
4647
Use: "current",
4748
Short: "Show the current selected organization the cli will use",
4849
Middleware: clibase.Chain(
4950
r.InitClient(client),
5051
),
52+
Options: clibase.OptionSet{
53+
{
54+
Name: "only-id",
55+
Description: "Only print the organization ID.",
56+
Required: false,
57+
Flag: "only-id",
58+
Value: clibase.BoolOf(&onlyID),
59+
},
60+
},
5161
Handler: func(inv *clibase.Invocation) error {
5262
org, err := CurrentOrganization(r, inv, client)
5363
if err != nil {
5464
return err
5565
}
5666

57-
out, err := formatter.Format(inv.Context(), []codersdk.Organization{org})
58-
if err != nil {
59-
return err
67+
if onlyID {
68+
_, _ = fmt.Fprintf(inv.Stdout, "%s\n", org.ID)
69+
} else {
70+
out, err := formatter.Format(inv.Context(), []codersdk.Organization{org})
71+
if err != nil {
72+
return err
73+
}
74+
_, err = fmt.Fprintf(inv.Stdout, out)
6075
}
61-
_, err = fmt.Fprintln(inv.Stdout, out)
6276
return nil
6377
},
6478
}

0 commit comments

Comments
 (0)