implement logs

This commit is contained in:
daveberrys committed 2026-07-18 02:02:55 +08:00
1 parent 772b4cade9
commit f380c3c581
3 files changed
+24 -6

No files matched your search

+1 -3
View File
@@ -8,9 +8,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func init() { func init() { rootCmd.AddCommand(commitCmd) }
rootCmd.AddCommand(commitCmd)
}
var commitCmd = &cobra.Command{ var commitCmd = &cobra.Command{
Use: "commit [files] [message] [description]", Use: "commit [files] [message] [description]",
+20
View File
@@ -0,0 +1,20 @@
package cmd
import (
"github.com/daveberrys/guh/src/utils"
"github.com/spf13/cobra"
)
func init() { rootCmd.AddCommand(logCmd) }
var logCmd = &cobra.Command{
Use: "logs [commits]",
Short: "Show commits logs.",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return utils.RunGitSequence(false, []string{"log"})
}
return utils.RunGitSequence(false, []string{"log", "-"+args[0]})
},
}
+3 -3
View File
@@ -3,7 +3,7 @@ package utils
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io" // "io"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
@@ -20,8 +20,8 @@ func RunGit(hideOutput bool, args ...string) (string, error) {
gitCmd.Stdout = &stdout gitCmd.Stdout = &stdout
gitCmd.Stderr = &stderr gitCmd.Stderr = &stderr
} else { } else {
gitCmd.Stdout = io.MultiWriter(os.Stdout, &stdout) gitCmd.Stdout = os.Stdout
gitCmd.Stderr = io.MultiWriter(os.Stderr, &stderr) gitCmd.Stderr = os.Stderr
} }
err := gitCmd.Run() err := gitCmd.Run()