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

Commit995b813

Browse files
committed
feat: add coder organizations switch to change org context
1 parentcad75c2 commit995b813

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎cli/organization.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package cli
22

33
import (
4+
"errors"
45
"fmt"
6+
"os"
57

68
"github.com/coder/coder/v2/cli/clibase"
79
"github.com/coder/coder/v2/cli/cliui"
@@ -27,6 +29,45 @@ func (r *RootCmd) organizations() *clibase.Cmd {
2729
returncmd
2830
}
2931

32+
func (r*RootCmd)switchOrganization()*clibase.Cmd {
33+
var (
34+
client=new(codersdk.Client)
35+
)
36+
37+
cmd:=&clibase.Cmd{
38+
Use:"switch <organization name | ID>",
39+
Short:"Switch the organization used by the cli. Pass an empty string to reset to the default organization.",
40+
Long:"Switch the organization used by the cli. Pass an empty string to reset to the default organization.\n"+formatExamples(
41+
example{
42+
Description:"Remove the current organization and defer to the default.",
43+
Command:"coder organizations switch ''",
44+
},
45+
example{
46+
Description:"Switch to a custom organization.",
47+
Command:"coder organizations switch my-org",
48+
},
49+
),
50+
Middleware:clibase.Chain(
51+
r.InitClient(client),
52+
),
53+
Options: clibase.OptionSet{},
54+
Handler:func(inv*clibase.Invocation)error {
55+
conf:=r.createConfig()
56+
// If the user passes an empty string, we want to remove the organization
57+
ifinv.Args[0]=="" {
58+
err:=conf.Organization().Delete()
59+
iferr!=nil&&!errors.Is(err,os.ErrNotExist) {
60+
returnfmt.Errorf("failed to unset organization: %w",err)
61+
}
62+
}
63+
64+
returnnil
65+
},
66+
}
67+
68+
returncmd
69+
}
70+
3071
func (r*RootCmd)currentOrganization()*clibase.Cmd {
3172
var (
3273
client=new(codersdk.Client)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp