Skip to content

Commit 728c7a4

Browse files
committed
feat: add groups support to the CLI
- Adds a route to get a group by org and name.
1 parent afb806f commit 728c7a4

28 files changed

+750
-18
lines changed

cli/cliui/table.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
166166
if val != nil {
167167
v = val.String()
168168
}
169+
case []string:
170+
//nolint
171+
v = strings.Join(v.([]string), ", ")
169172
}
170173

171174
rowSlice[i] = v

cli/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func create() *cobra.Command {
3333
return err
3434
}
3535

36-
organization, err := currentOrganization(cmd, client)
36+
organization, err := CurrentOrganization(cmd, client)
3737
if err != nil {
3838
return err
3939
}

cli/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func login() *cobra.Command {
8686
return xerrors.Errorf("Failed to check server %q for first user, is the URL correct and is coder accessible from your browser? Error - has initial user: %w", serverURL.String(), err)
8787
}
8888
if !hasInitialUser {
89-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"Your Coder deployment hasn't been set up!\n")
89+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Caret+"Your Coder deployment hasn't been set up!\n")
9090

9191
if username == "" {
9292
if !isTTY(cmd) {
@@ -244,7 +244,7 @@ func login() *cobra.Command {
244244
return xerrors.Errorf("write server url: %w", err)
245245
}
246246

247-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"Welcome to Coder, %s! You're authenticated.\n", cliui.Styles.Keyword.Render(resp.Username))
247+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Caret+"Welcome to Coder, %s! You're authenticated.\n", cliui.Styles.Keyword.Render(resp.Username))
248248
return nil
249249
},
250250
}

cli/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func logout() *cobra.Command {
6767
errorString := strings.TrimRight(errorStringBuilder.String(), "\n")
6868
return xerrors.New("Failed to log out.\n" + errorString)
6969
}
70-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"You are no longer logged in. You can log in using 'coder login <url>'.\n")
70+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Caret+"You are no longer logged in. You can log in using 'coder login <url>'.\n")
7171
return nil
7272
},
7373
}

cli/parameterslist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func parameterList() *cobra.Command {
2727
return err
2828
}
2929

30-
organization, err := currentOrganization(cmd, client)
30+
organization, err := CurrentOrganization(cmd, client)
3131
if err != nil {
3232
return xerrors.Errorf("get current organization: %w", err)
3333
}

cli/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
)
3030

3131
var (
32-
caret = cliui.Styles.Prompt.String()
32+
Caret = cliui.Styles.Prompt.String()
3333

3434
// Applied as annotations to workspace commands
3535
// so they display in a separated "help" section.
@@ -114,7 +114,7 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
114114
Use: "coder",
115115
SilenceErrors: true,
116116
SilenceUsage: true,
117-
Long: fmt.Sprintf(fmtLong, buildinfo.Version()),
117+
Long: fmt.Sprintf(fmtLong, buildinfo.Version()),
118118
PersistentPreRun: func(cmd *cobra.Command, args []string) {
119119
if cliflag.IsSetBool(cmd, varNoVersionCheck) &&
120120
cliflag.IsSetBool(cmd, varNoFeatureWarning) {
@@ -328,8 +328,8 @@ func createAgentClient(cmd *cobra.Command) (*codersdk.Client, error) {
328328
return client, nil
329329
}
330330

331-
// currentOrganization returns the currently active organization for the authenticated user.
332-
func currentOrganization(cmd *cobra.Command, client *codersdk.Client) (codersdk.Organization, error) {
331+
// CurrentOrganization returns the currently active organization for the authenticated user.
332+
func CurrentOrganization(cmd *cobra.Command, client *codersdk.Client) (codersdk.Organization, error) {
333333
orgs, err := client.OrganizationsByUser(cmd.Context(), codersdk.Me)
334334
if err != nil {
335335
return codersdk.Organization{}, nil

cli/templatecreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func templateCreate() *cobra.Command {
4040
return err
4141
}
4242

43-
organization, err := currentOrganization(cmd, client)
43+
organization, err := CurrentOrganization(cmd, client)
4444
if err != nil {
4545
return err
4646
}

cli/templatedelete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func templateDelete() *cobra.Command {
2727
if err != nil {
2828
return err
2929
}
30-
organization, err := currentOrganization(cmd, client)
30+
organization, err := CurrentOrganization(cmd, client)
3131
if err != nil {
3232
return err
3333
}

cli/templateedit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func templateEdit() *cobra.Command {
2929
if err != nil {
3030
return xerrors.Errorf("create client: %w", err)
3131
}
32-
organization, err := currentOrganization(cmd, client)
32+
organization, err := CurrentOrganization(cmd, client)
3333
if err != nil {
3434
return xerrors.Errorf("get current organization: %w", err)
3535
}

cli/templatelist.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func templateList() *cobra.Command {
2020
if err != nil {
2121
return err
2222
}
23-
organization, err := currentOrganization(cmd, client)
23+
organization, err := CurrentOrganization(cmd, client)
2424
if err != nil {
2525
return err
2626
}
@@ -30,7 +30,7 @@ func templateList() *cobra.Command {
3030
}
3131

3232
if len(templates) == 0 {
33-
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "%s No templates found in %s! Create one:\n\n", caret, color.HiWhiteString(organization.Name))
33+
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "%s No templates found in %s! Create one:\n\n", Caret, color.HiWhiteString(organization.Name))
3434
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), color.HiMagentaString(" $ coder templates create <directory>\n"))
3535
return nil
3636
}

0 commit comments

Comments
 (0)