github.com/yourbase/yb@v0.7.1/cmd/yb/token.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/spf13/cobra" 8 "github.com/yourbase/yb/internal/config" 9 ) 10 11 // tokenCmd represents an invocation of `yb token`, which outputs the saved 12 // token from `yb login` to stdout. This can be used 13 type tokenCmd struct { 14 cfg config.Getter 15 } 16 17 func newTokenCmd(cfg config.Getter) *cobra.Command { 18 p := &tokenCmd{cfg: cfg} 19 return &cobra.Command{ 20 Use: "token", 21 Short: "Print an auth token", 22 Long: `Print a YourBase auth token to stdout. Compose this with other tools to interact with the YourBase API more easily.`, 23 Args: cobra.NoArgs, 24 SilenceErrors: true, 25 SilenceUsage: true, 26 RunE: func(cmd *cobra.Command, args []string) error { 27 return p.run(cmd.Context()) 28 }, 29 } 30 } 31 32 func (cmd *tokenCmd) run(ctx context.Context) error { 33 token := config.Get(cmd.cfg, "user", "api_key") 34 _, err := fmt.Println(token) 35 return err 36 }