mirror of
https://github.com/daveberrys/guh.git
synced 2026-11-29 00:26:46 +08:00
optional to hide outputs.
This commit is contained in:
1 parent
61ac03e7b4
commit
70144e6ee0
8 files changed
+22
-16
No files matched your search
+4
-4
@@ -18,7 +18,7 @@ var commitCmd = &cobra.Command{
|
||||
Args: cobra.RangeArgs(0, 3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return utils.RunGit("status", "--short")
|
||||
return utils.RunGitSequence(false, []string{"status", "--short"})
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
@@ -37,18 +37,18 @@ var commitCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
fmt.Println("Edited files:")
|
||||
if err := utils.RunGit("status", "--short"); err != nil {
|
||||
if err := utils.RunGitSequence(false, []string{"status", "--short"}); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
utils.RunGitSequence(addArgs)
|
||||
utils.RunGitSequence(false, addArgs)
|
||||
|
||||
commitArgs := []string{"commit", "-m", args[1]}
|
||||
if len(args) == 3 {
|
||||
commitArgs = append(commitArgs, "-m", args[2])
|
||||
}
|
||||
utils.RunGitSequence(commitArgs)
|
||||
utils.RunGitSequence(false, commitArgs)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
+1
-1
@@ -24,7 +24,7 @@ var createBranchCmd = &cobra.Command{
|
||||
Short: "Create and switch to a branch",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return utils.RunGitSequence([]string{"switch", "-c", args[0]})
|
||||
return utils.RunGitSequence(false, []string{"switch", "-c", args[0]})
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -14,6 +14,6 @@ var diffCmd = &cobra.Command{
|
||||
Short: "Show working tree changes",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return utils.RunGitSequence([]string{"diff"})
|
||||
return utils.RunGitSequence(false, []string{"diff"})
|
||||
},
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@ var pullCmd = &cobra.Command{
|
||||
Short: "Fetch and pull updates",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return utils.RunGitSequence(
|
||||
return utils.RunGitSequence(false,
|
||||
[]string{"fetch"},
|
||||
[]string{"pull"},
|
||||
)
|
||||
|
||||
+1
-1
@@ -14,6 +14,6 @@ var pushCmd = &cobra.Command{
|
||||
Short: "Add current changes and push",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return utils.RunGitSequence([]string{"push"})
|
||||
return utils.RunGitSequence(false, []string{"push"})
|
||||
},
|
||||
}
|
||||
+1
-1
@@ -14,6 +14,6 @@ var stashCmd = &cobra.Command{
|
||||
Short: "Stash current changes",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return utils.RunGitSequence([]string{"stash"})
|
||||
return utils.RunGitSequence(false, []string{"stash"})
|
||||
},
|
||||
}
|
||||
+2
-2
@@ -44,7 +44,7 @@ func performAccountSwitch(username string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := utils.RunGitSequence(
|
||||
if err := utils.RunGitSequence(false,
|
||||
[]string{"config", "--global", "user.name", account.Username},
|
||||
[]string{"config", "--global", "user.email", account.Email},
|
||||
); err != nil {
|
||||
@@ -66,5 +66,5 @@ func performAccountSwitch(username string) error {
|
||||
}
|
||||
|
||||
func performBranchSwitch(branchName string) error {
|
||||
return utils.RunGitSequence([]string{"switch", branchName})
|
||||
return utils.RunGitSequence(false, []string{"switch", branchName})
|
||||
}
|
||||
+11
-5
@@ -2,23 +2,29 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func RunGit(args ...string) error {
|
||||
func RunGit(hideOutput bool, args ...string) error {
|
||||
gitCmd := exec.Command("git", args...)
|
||||
gitCmd.Stdin = os.Stdin
|
||||
gitCmd.Stdout = os.Stdout
|
||||
gitCmd.Stderr = os.Stderr
|
||||
if hideOutput {
|
||||
gitCmd.Stdout = io.Discard
|
||||
gitCmd.Stderr = io.Discard
|
||||
} else {
|
||||
gitCmd.Stdout = os.Stdout
|
||||
gitCmd.Stderr = os.Stderr
|
||||
}
|
||||
|
||||
return gitCmd.Run()
|
||||
}
|
||||
|
||||
func RunGitSequence(commands ...[]string) error {
|
||||
func RunGitSequence(hideOutput bool, commands ...[]string) error {
|
||||
for _, commandArgs := range commands {
|
||||
if err := RunGit(commandArgs...); err != nil {
|
||||
if err := RunGit(hideOutput, commandArgs...); err != nil {
|
||||
return fmt.Errorf("git %s failed: %w", strings.Join(commandArgs, " "), err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user