MCPcopy Create free account
hub / github.com/basecamp/hey-cli / newAuthTokenCommand

Function newAuthTokenCommand

internal/cmd/auth.go:250–277  ·  view source on GitHub ↗

token subcommand

()

Source from the content-addressed store, hash-verified

248// token subcommand
249
250func newAuthTokenCommand() *cobra.Command {
251 var stored bool
252
253 cmd := &cobra.Command{
254 Use: "token",
255 Short: "Print access token to stdout",
256 RunE: func(cmd *cobra.Command, args []string) error {
257 if !stored {
258 if envToken := os.Getenv("HEY_TOKEN"); envToken != "" {
259 fmt.Fprint(cmd.OutOrStdout(), envToken)
260 return nil
261 }
262 }
263
264 ctx := context.Background()
265 token, err := authMgr.AccessToken(ctx)
266 if err != nil {
267 return output.ErrAuth(fmt.Sprintf("could not get token: %v", err))
268 }
269 fmt.Fprint(cmd.OutOrStdout(), token)
270 return nil
271 },
272 }
273
274 cmd.Flags().BoolVar(&stored, "stored", false, "Only print stored OAuth token (ignore HEY_TOKEN env var)")
275
276 return cmd
277}

Callers 1

newAuthCommandFunction · 0.85

Calls 1

AccessTokenMethod · 0.80

Tested by

no test coverage detected