MCPcopy Index your code
hub / github.com/cli/cli / NewCmdToken

Function NewCmdToken

pkg/cmd/auth/token/token.go:23–55  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*TokenOptions) error)

Source from the content-addressed store, hash-verified

21}
22
23func NewCmdToken(f *cmdutil.Factory, runF func(*TokenOptions) error) *cobra.Command {
24 opts := &TokenOptions{
25 IO: f.IOStreams,
26 Config: f.Config,
27 }
28
29 cmd := &cobra.Command{
30 Use: "token",
31 Short: "Print the authentication token gh uses for a hostname and account",
32 Long: heredoc.Docf(`
33 This command outputs the authentication token for an account on a given GitHub host.
34
35 Without the %[1]s--hostname%[1]s flag, the default host is chosen.
36
37 Without the %[1]s--user%[1]s flag, the active account for the host is chosen.
38 `, "`"),
39 Args: cobra.ExactArgs(0),
40 RunE: func(cmd *cobra.Command, args []string) error {
41 if runF != nil {
42 return runF(opts)
43 }
44
45 return tokenRun(opts)
46 },
47 }
48
49 cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "The hostname of the GitHub instance authenticated with")
50 cmd.Flags().StringVarP(&opts.Username, "user", "u", "", "The account to output the token for")
51 cmd.Flags().BoolVarP(&opts.SecureStorage, "secure-storage", "", false, "Search only secure credential store for authentication token")
52 _ = cmd.Flags().MarkHidden("secure-storage")
53
54 return cmd
55}
56
57func tokenRun(opts *TokenOptions) error {
58 cfg, err := opts.Config()

Callers 1

TestNewCmdTokenFunction · 0.85

Calls 1

tokenRunFunction · 0.85

Tested by 1

TestNewCmdTokenFunction · 0.68