From 53419329a0e0eb9c3f950522ea49fba1a66056a4 Mon Sep 17 00:00:00 2001 From: Slug-Boi Date: Thu, 10 Apr 2025 22:31:44 +0200 Subject: [PATCH] refactor: no args means tui opens --- src/cmd/gh.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/cmd/gh.go b/src/cmd/gh.go index b29de2c..c7ce7bc 100644 --- a/src/cmd/gh.go +++ b/src/cmd/gh.go @@ -1,13 +1,13 @@ -/* -Copyright © 2025 NAME HERE -*/ package cmd import ( "fmt" + "os" + "strings" "github.com/Slug-Boi/cocommit/src/cmd/tui" "github.com/Slug-Boi/cocommit/src/cmd/utils" + //"github.com/charmbracelet/lipgloss" "github.com/spf13/cobra" ) @@ -20,7 +20,7 @@ func GHCmd () *cobra.Command { Long: `This command will create add a github profile to your author list. You just have to run the command with a username of the github profile you want to add. The email will be added manually by following the TUI or adding the email flag to the command.`, - Args: cobra.ExactArgs(1), + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { email, _ := cmd.Flags().GetString("email") shortname, _ := cmd.Flags().GetString("shortname") @@ -29,6 +29,19 @@ func GHCmd () *cobra.Command { groups, _ := cmd.Flags().GetStringSlice("groups") exclude, _ := cmd.Flags().GetBool("exclude") + if len(args) == 0 { + username, email_out, err := tui.RunForm() + if err != nil { + panic(fmt.Sprintf("Error: %v", err)) + } + if username == "" { + os.Exit(0) + } + + args = append(args, username) + email = strings.TrimSpace(email_out) + } + user := utils.FetchGithubProfile(args[0]) // Update values if flags are set