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

Commit3106518

Browse files
committed
feat: add coder organizations switch to change org context
1 parentd4d20af commit3106518

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

‎cli/organization.go

Lines changed: 41 additions & 1 deletion
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"
@@ -14,7 +16,6 @@ func (r *RootCmd) organizations() *clibase.Cmd {
1416
Use:"organizations { current }",
1517
Short:"Organization related commands",
1618
Aliases: []string{"organization","org","orgs"},
17-
1819
Handler:func(inv*clibase.Invocation)error {
1920
returninv.Command.HelpHandler(inv)
2021
},
@@ -27,6 +28,45 @@ func (r *RootCmd) organizations() *clibase.Cmd {
2728
returncmd
2829
}
2930

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp