From 527269f788ab4c00943e0276955adaf45757d2c5 Mon Sep 17 00:00:00 2001 From: Theis Date: Thu, 10 Oct 2024 21:42:16 +0200 Subject: [PATCH] refactor: change root command to include commit wrapper options --- go.mod | 28 ++++++++++++++++++++++++---- src_code/go_src/cmd/root.go | 29 ++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 0954662..d5fea6d 100644 --- a/go.mod +++ b/go.mod @@ -2,18 +2,38 @@ module main go 1.21.0 -require dagger.io/dagger v0.10.0 +require ( + dagger.io/dagger v0.10.0 + github.com/charmbracelet/bubbles v0.20.0 + github.com/charmbracelet/bubbletea v1.1.1 + github.com/charmbracelet/lipgloss v0.13.0 + github.com/spf13/cobra v1.8.1 +) require ( github.com/99designs/gqlgen v0.17.31 // indirect github.com/Khan/genqlient v0.6.0 // indirect github.com/adrg/xdg v0.4.0 // indirect + github.com/atotto/clipboard v0.1.4 // indirect + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/charmbracelet/x/ansi v0.2.3 // indirect + github.com/charmbracelet/x/term v0.2.0 // indirect + github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-localereader v0.0.1 // indirect + github.com/mattn/go-runewidth v0.0.16 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/spf13/cobra v1.8.1 // indirect + github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect + github.com/muesli/cancelreader v0.2.2 // indirect + github.com/muesli/termenv v0.15.2 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + github.com/sahilm/fuzzy v0.1.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/vektah/gqlparser/v2 v2.5.6 // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect - golang.org/x/sync v0.6.0 // indirect - golang.org/x/sys v0.14.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect ) diff --git a/src_code/go_src/cmd/root.go b/src_code/go_src/cmd/root.go index f2c0e49..4e8c167 100644 --- a/src_code/go_src/cmd/root.go +++ b/src_code/go_src/cmd/root.go @@ -1,9 +1,10 @@ package cmd import ( + "fmt" + "main/src_code/go_src/cmd/tui" "main/src_code/go_src/cmd/utils" "os" - "fmt" "github.com/spf13/cobra" ) @@ -26,13 +27,31 @@ var rootCmd = &cobra.Command{ pflag, _ := cmd.Flags().GetBool("print") // run execute commands again as root run will not call this part // redundant check for now but will be useful later when we add tui - if len(args) == 1 { - utils.GitWrapper(args[0]) - if pflag { - fmt.Println(args[0]) + wrap_around: + switch len(args) { + case 0: + // launch the tui + sel_auth := tui.Entry() + for _, a := range sel_auth { + fmt.Println(a) } os.Exit(0) + case 1: + if len(args) == 1 { + utils.GitWrapper(args[0]) + if pflag { + fmt.Println(args[0]) + } + os.Exit(0) + } } + + // check if user included -m tag and remove. Wrap around for safety's sake + if args[0] == "-m" { + args = args[1:] + goto wrap_around + } + // builds the commit message with the selected authors message := utils.Commit(args[0], args[1:]) // prints the commit message to the console if the print flag is set