refactor: log errors

This commit is contained in:
Stavros
2025-01-24 18:24:20 +02:00
parent 35854f5ce4
commit f61b6dbad4
6 changed files with 19 additions and 28 deletions

View File

@@ -3,7 +3,6 @@ package create
import (
"errors"
"fmt"
"os"
"strings"
"github.com/charmbracelet/huh"
@@ -18,9 +17,9 @@ var password string
var docker bool
var CreateCmd = &cobra.Command{
Use: "create",
Use: "create",
Short: "Create a user",
Long: `Create a user either interactively or by passing flags.`,
Long: `Create a user either interactively or by passing flags.`,
Run: func(cmd *cobra.Command, args []string) {
if interactive {
form := huh.NewForm(
@@ -47,13 +46,11 @@ var CreateCmd = &cobra.Command{
if formErr != nil {
log.Fatal().Err(formErr).Msg("Form failed")
os.Exit(1)
}
}
if username == "" || password == "" {
log.Error().Msg("Username and password cannot be empty")
os.Exit(1)
}
log.Info().Str("username", username).Str("password", password).Bool("docker", docker).Msg("Creating user")
@@ -62,7 +59,6 @@ var CreateCmd = &cobra.Command{
if passwordErr != nil {
log.Fatal().Err(passwordErr).Msg("Failed to hash password")
os.Exit(1)
}
passwordString := string(passwordByte)
@@ -80,4 +76,4 @@ func init() {
CreateCmd.Flags().BoolVar(&docker, "docker", false, "Format output for docker")
CreateCmd.Flags().StringVar(&username, "username", "", "Username")
CreateCmd.Flags().StringVar(&password, "password", "", "Password")
}
}