refactor: build cobra commands with constructors

This commit is contained in:
Mathis Maquenne
2026-08-05 11:35:52 +02:00
parent 0ab25addd5
commit 3c9da5f24a
6 changed files with 121 additions and 111 deletions
+21 -23
View File
@@ -7,31 +7,29 @@ import (
"github.com/spf13/cobra"
)
var loginCmd = &cobra.Command{
Use: "login",
Short: "Log in to Deezer with your email and password",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if err := auth.CheckGatewayEnv(); err != nil {
return err
}
func newLoginCmd() *cobra.Command {
return &cobra.Command{
Use: "login",
Short: "Log in to Deezer with your email and password",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if err := auth.CheckGatewayEnv(); err != nil {
return err
}
email, password, err := auth.PromptCredentials()
if err != nil {
return err
}
email, password, err := auth.PromptCredentials()
if err != nil {
return err
}
_, username, err := auth.Login(cmd.Context(), email, password)
if err != nil {
return err
}
_, username, err := auth.Login(cmd.Context(), email, password)
if err != nil {
return err
}
fmt.Printf("Successfully logged in as %s.\n", username)
fmt.Printf("Successfully logged in as %s.\n", username)
return nil
},
}
func init() {
RootCmd.AddCommand(loginCmd)
return nil
},
}
}