MCPcopy
hub / github.com/cli/cli / NewCmdSwitch

Function NewCmdSwitch

pkg/cmd/auth/switch/switch.go:24–67  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*SwitchOptions) error)

Source from the content-addressed store, hash-verified

22}
23
24func NewCmdSwitch(f *cmdutil.Factory, runF func(*SwitchOptions) error) *cobra.Command {
25 opts := SwitchOptions{
26 IO: f.IOStreams,
27 Config: f.Config,
28 Prompter: f.Prompter,
29 }
30
31 cmd := &cobra.Command{
32 Use: "switch",
33 Args: cobra.ExactArgs(0),
34 Short: "Switch active GitHub account",
35 Long: heredoc.Docf(`
36 Switch the active account for a GitHub host.
37
38 This command changes the authentication configuration that will
39 be used when running commands targeting the specified GitHub host.
40
41 If the specified host has two accounts, the active account will be switched
42 automatically. If there are more than two accounts, disambiguation will be
43 required either through the %[1]s--user%[1]s flag or an interactive prompt.
44
45 For a list of authenticated accounts you can run %[1]sgh auth status%[1]s.
46 `, "`"),
47 Example: heredoc.Doc(`
48 # Select what host and account to switch to via a prompt
49 $ gh auth switch
50
51 # Switch the active account on a specific host to a specific user
52 $ gh auth switch --hostname enterprise.internal --user monalisa
53 `),
54 RunE: func(c *cobra.Command, args []string) error {
55 if runF != nil {
56 return runF(&opts)
57 }
58
59 return switchRun(&opts)
60 },
61 }
62
63 cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "The hostname of the GitHub instance to switch account for")
64 cmd.Flags().StringVarP(&opts.Username, "user", "u", "", "The account to switch to")
65
66 return cmd
67}
68
69type hostUser struct {
70 host string

Callers 1

TestNewCmdSwitchFunction · 0.85

Calls 1

switchRunFunction · 0.85

Tested by 1

TestNewCmdSwitchFunction · 0.68