From ad0dc7c89d09e5254ab71d151ad84ed940bf850f Mon Sep 17 00:00:00 2001 From: Daveberry <84567826+daveberrys@users.noreply.github.com> Date: Wed, 10 Jun 2026 15:57:32 +0800 Subject: [PATCH] any errors goes one liners --- go.mod | 3 ++- install_guh.sh | 23 +++++++++++++++++++++++ src/cmd/commit.go | 4 +--- src/cmd/create.go | 4 +--- src/cmd/switch.go | 16 ++++------------ 5 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 install_guh.sh diff --git a/go.mod b/go.mod index f865871..b32d5f8 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,9 @@ module github.com/daveberrys/guh go 1.26.3 +require github.com/spf13/cobra v1.10.2 + require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/spf13/cobra v1.10.2 // indirect github.com/spf13/pflag v1.0.9 // indirect ) diff --git a/install_guh.sh b/install_guh.sh new file mode 100644 index 0000000..2315d22 --- /dev/null +++ b/install_guh.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "This will install the compiled local 'guh' binary to '~/.local/bin' directory." +read -p "Do you want to continue? [y/n]: " choice + +if [ "$choice" != "Y" ] && [ "$choice" != "y" ]; then + echo "Installation cancelled." + exit 0 +fi + +echo "Installing..." +echo + +go mod tidy && echo "Tidied go.mod and go.sum files." +go get ./ && echo "Installed all packages." || echo "Failed to install all packages." +go build && echo "Built 'guh' binary." || echo "Failed to build 'guh' binary." +echo + +cp guh ~/.local/bin/guh && echo "Successfully placed 'guh' in '~/.local/bin' directory." || echo "Failed to place 'guh' in '~/.local/bin' directory." +chmod +x ~/.local/bin/guh && echo "Successfully made 'guh' executable." || echo "Failed to make 'guh' executable." + +guh >> /dev/null && echo "Successfully installed 'guh' binary." || echo "Failed to install 'guh' binary." +echo "Installation complete." \ No newline at end of file diff --git a/src/cmd/commit.go b/src/cmd/commit.go index 8ca5e5f..74a13a4 100644 --- a/src/cmd/commit.go +++ b/src/cmd/commit.go @@ -37,9 +37,7 @@ var commitCmd = &cobra.Command{ } fmt.Println("Edited files:") - if err := utils.RunGitSequence(false, []string{"status", "--short"}); err != nil { - return err - } + if err := utils.RunGitSequence(false, []string{"status", "--short"}); err != nil { return err } fmt.Println() utils.RunGitSequence(false, addArgs) diff --git a/src/cmd/create.go b/src/cmd/create.go index 4bd6e58..f11ca1e 100644 --- a/src/cmd/create.go +++ b/src/cmd/create.go @@ -42,9 +42,7 @@ var createAccountCmd = &cobra.Command{ return fmt.Errorf("username, email, and classicToken are required") } - if err := utils.UpsertAccount(account); err != nil { - return err - } + if err := utils.UpsertAccount(account); err != nil { return err } fmt.Printf("Saved account: %s\n", account.Username) return nil diff --git a/src/cmd/switch.go b/src/cmd/switch.go index 963f566..7100d3f 100644 --- a/src/cmd/switch.go +++ b/src/cmd/switch.go @@ -40,26 +40,18 @@ var switchAccountCmd = &cobra.Command{ func performAccountSwitch(username string) error { account, err := utils.FindAccount(username) - if err != nil { - return err - } + if err != nil { return err } if err := utils.RunGitSequence(false, []string{"config", "--global", "user.name", account.Username}, []string{"config", "--global", "user.email", account.Email}, - ); err != nil { - return err - } + ); err != nil { return err } homeDir, err := os.UserHomeDir() - if err != nil { - return err - } + if err != nil { return err } credentials := fmt.Sprintf("https://%s:%s@github.com\n", account.Username, account.ClassicToken) - if err := os.WriteFile(filepath.Join(homeDir, ".git-credentials"), []byte(credentials), 0600); err != nil { - return err - } + if err := os.WriteFile(filepath.Join(homeDir, ".git-credentials"), []byte(credentials), 0600); err != nil { return err } fmt.Printf("Switched to account: %s\n", account.Username) return nil