diff --git a/pkg/cmd/apitoken/apitoken.go b/pkg/cmd/apitoken/apitoken.go new file mode 100644 index 00000000..37117bbe --- /dev/null +++ b/pkg/cmd/apitoken/apitoken.go @@ -0,0 +1,25 @@ +package apitoken + +import ( + "fmt" + + "github.com/depot/cli/pkg/config" + "github.com/spf13/cobra" +) + +func NewCmdApiToken() *cobra.Command { + cmd := &cobra.Command{ + Use: "api-token", + Short: "Get the API token for a Depot login", + RunE: func(cmd *cobra.Command, args []string) error { + token := config.GetApiToken() + if token == "" { + return fmt.Errorf("missing API token, please run `depot login`") + } + + fmt.Println(token) + return nil + }, + } + return cmd +} diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index 2d2a42c2..4a20a377 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" + apiTokenCmd "github.com/depot/cli/pkg/cmd/apitoken" bakeCmd "github.com/depot/cli/pkg/cmd/bake" "github.com/depot/cli/pkg/cmd/blog" buildCmd "github.com/depot/cli/pkg/cmd/build" @@ -62,6 +63,7 @@ func NewCmdRoot(version, buildDate string) *cobra.Command { _ = cmd.PersistentFlags().MarkHidden("config") // Child commands + cmd.AddCommand(apiTokenCmd.NewCmdApiToken()) cmd.AddCommand(bakeCmd.NewCmdBake()) cmd.AddCommand(blog.NewCmdBlog()) cmd.AddCommand(buildCmd.NewCmdBuild())