Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit70dc282

Browse files
authored
feat(cli): add favorite/unfavorite commands (#11793)
1 parentf92336c commit70dc282

File tree

10 files changed

+179
-0
lines changed

10 files changed

+179
-0
lines changed

‎cli/favorite.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
"golang.org/x/xerrors"
7+
8+
"github.com/coder/coder/v2/cli/clibase"
9+
"github.com/coder/coder/v2/codersdk"
10+
)
11+
12+
func (r*RootCmd)favorite()*clibase.Cmd {
13+
client:=new(codersdk.Client)
14+
cmd:=&clibase.Cmd{
15+
Aliases: []string{"fav","favou"+"rite"},
16+
Annotations:workspaceCommand,
17+
Use:"favorite <workspace>",
18+
Short:"Add a workspace to your favorites",
19+
Middleware:clibase.Chain(
20+
clibase.RequireNArgs(1),
21+
r.InitClient(client),
22+
),
23+
Handler:func(inv*clibase.Invocation)error {
24+
ws,err:=namedWorkspace(inv.Context(),client,inv.Args[0])
25+
iferr!=nil {
26+
returnxerrors.Errorf("get workspace: %w",err)
27+
}
28+
29+
iferr:=client.FavoriteWorkspace(inv.Context(),ws.ID);err!=nil {
30+
returnxerrors.Errorf("favorite workspace: %w",err)
31+
}
32+
_,_=fmt.Fprintf(inv.Stdout,"Workspace %q added to favorites.\n",ws.Name)
33+
returnnil
34+
},
35+
}
36+
returncmd
37+
}
38+
39+
func (r*RootCmd)unfavorite()*clibase.Cmd {
40+
client:=new(codersdk.Client)
41+
cmd:=&clibase.Cmd{
42+
Aliases: []string{"unfav","unfavou"+"rite"},
43+
Annotations:workspaceCommand,
44+
Use:"unfavorite <workspace>",
45+
Short:"Remove a workspace from your favorites",
46+
Middleware:clibase.Chain(
47+
clibase.RequireNArgs(1),
48+
r.InitClient(client),
49+
),
50+
Handler:func(inv*clibase.Invocation)error {
51+
ws,err:=namedWorkspace(inv.Context(),client,inv.Args[0])
52+
iferr!=nil {
53+
returnxerrors.Errorf("get workspace: %w",err)
54+
}
55+
56+
iferr:=client.UnfavoriteWorkspace(inv.Context(),ws.ID);err!=nil {
57+
returnxerrors.Errorf("unfavorite workspace: %w",err)
58+
}
59+
_,_=fmt.Fprintf(inv.Stdout,"Workspace %q removed from favorites.\n",ws.Name)
60+
returnnil
61+
},
62+
}
63+
returncmd
64+
}

‎cli/favorite_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cli_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/coder/coder/v2/cli/clitest"
8+
"github.com/coder/coder/v2/coderd/coderdtest"
9+
"github.com/coder/coder/v2/coderd/database"
10+
"github.com/coder/coder/v2/coderd/database/dbfake"
11+
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
funcTestFavoriteUnfavorite(t*testing.T) {
16+
t.Parallel()
17+
18+
var (
19+
client,db=coderdtest.NewWithDatabase(t,nil)
20+
owner=coderdtest.CreateFirstUser(t,client)
21+
memberClient,member=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID)
22+
ws=dbfake.WorkspaceBuild(t,db, database.Workspace{OwnerID:member.ID,OrganizationID:owner.OrganizationID}).Do()
23+
)
24+
25+
inv,root:=clitest.New(t,"favorite",ws.Workspace.Name)
26+
clitest.SetupConfig(t,memberClient,root)
27+
28+
varbuf bytes.Buffer
29+
inv.Stdout=&buf
30+
err:=inv.Run()
31+
require.NoError(t,err)
32+
33+
updated:=coderdtest.MustWorkspace(t,memberClient,ws.Workspace.ID)
34+
require.True(t,updated.Favorite)
35+
36+
buf.Reset()
37+
38+
inv,root=clitest.New(t,"unfavorite",ws.Workspace.Name)
39+
clitest.SetupConfig(t,memberClient,root)
40+
inv.Stdout=&buf
41+
err=inv.Run()
42+
require.NoError(t,err)
43+
updated=coderdtest.MustWorkspace(t,memberClient,ws.Workspace.ID)
44+
require.False(t,updated.Favorite)
45+
}

‎cli/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func (r *RootCmd) Core() []*clibase.Cmd {
100100
r.configSSH(),
101101
r.create(),
102102
r.deleteWorkspace(),
103+
r.favorite(),
103104
r.list(),
104105
r.open(),
105106
r.ping(),
@@ -112,6 +113,7 @@ func (r *RootCmd) Core() []*clibase.Cmd {
112113
r.start(),
113114
r.stat(),
114115
r.stop(),
116+
r.unfavorite(),
115117
r.update(),
116118

117119
// Hidden

‎cli/testdata/coder_--help.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SUBCOMMANDS:
2222
dotfiles Personalize your workspace by applying a canonical
2323
dotfiles repository
2424
external-auth Manage external authentication
25+
favorite Add a workspace to your favorites
2526
list List workspaces
2627
login Authenticate with Coder deployment
2728
logout Unauthenticate your local session
@@ -47,6 +48,7 @@ SUBCOMMANDS:
4748
stop Stop a workspace
4849
templates Manage templates
4950
tokens Manage personal access tokens
51+
unfavorite Remove a workspace from your favorites
5052
update Will update and start a given workspace if it is out of
5153
date
5254
users Manage users
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
coder v0.0.0-devel
2+
3+
USAGE:
4+
coder favorite <workspace>
5+
6+
Add a workspace to your favorites
7+
8+
Aliases: fav, favourite
9+
10+
———
11+
Run `coder --help` for a list of global options.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
coder v0.0.0-devel
2+
3+
USAGE:
4+
coder unfavorite <workspace>
5+
6+
Remove a workspace from your favorites
7+
8+
Aliases: unfav, unfavourite
9+
10+
———
11+
Run `coder --help` for a list of global options.

‎docs/cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Coder — A tool for provisioning self-hosted development environments with Terr
3131
|[<code>delete</code>](./cli/delete.md)| Delete a workspace|
3232
|[<code>dotfiles</code>](./cli/dotfiles.md)| Personalize your workspace by applying a canonical dotfiles repository|
3333
|[<code>external-auth</code>](./cli/external-auth.md)| Manage external authentication|
34+
|[<code>favorite</code>](./cli/favorite.md)| Add a workspace to your favorites|
3435
|[<code>features</code>](./cli/features.md)| List Enterprise features|
3536
|[<code>groups</code>](./cli/groups.md)| Manage groups|
3637
|[<code>licenses</code>](./cli/licenses.md)| Add, delete, and list licenses|
@@ -57,6 +58,7 @@ Coder — A tool for provisioning self-hosted development environments with Terr
5758
|[<code>stop</code>](./cli/stop.md)| Stop a workspace|
5859
|[<code>templates</code>](./cli/templates.md)| Manage templates|
5960
|[<code>tokens</code>](./cli/tokens.md)| Manage personal access tokens|
61+
|[<code>unfavorite</code>](./cli/unfavorite.md)| Remove a workspace from your favorites|
6062
|[<code>update</code>](./cli/update.md)| Will update and start a given workspace if it is out of date|
6163
|[<code>users</code>](./cli/users.md)| Manage users|
6264
|[<code>version</code>](./cli/version.md)| Show coder version|

‎docs/cli/favorite.md

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎docs/cli/unfavorite.md

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎docs/manifest.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,11 @@
617617
"description":"Print auth for an external provider",
618618
"path":"cli/external-auth_access-token.md"
619619
},
620+
{
621+
"title":"favorite",
622+
"description":"Add a workspace to your favorites",
623+
"path":"cli/favorite.md"
624+
},
620625
{
621626
"title":"features",
622627
"description":"List Enterprise features",
@@ -951,6 +956,11 @@
951956
"description":"Delete a token",
952957
"path":"cli/tokens_remove.md"
953958
},
959+
{
960+
"title":"unfavorite",
961+
"description":"Remove a workspace from your favorites",
962+
"path":"cli/unfavorite.md"
963+
},
954964
{
955965
"title":"update",
956966
"description":"Will update and start a given workspace if it is out of date",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp