mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
ExecuteCommand() moved into the utils dumping ground
This commit is contained in:
committed by
Chris Cummer
parent
de7480b221
commit
0b8a063487
@@ -1,10 +1,10 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -26,7 +26,7 @@ func NewClient() *Client {
|
||||
func (client *Client) CurrentBranch() string {
|
||||
arg := []string{"rev-parse", "--abbrev-ref", "HEAD"}
|
||||
cmd := exec.Command("git", arg...)
|
||||
str := executeCommand(cmd)
|
||||
str := wtf.ExecuteCommand(cmd)
|
||||
|
||||
return str
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func (client *Client) CurrentBranch() string {
|
||||
func (client *Client) ChangedFiles() []string {
|
||||
arg := []string{"status", "--porcelain"}
|
||||
cmd := exec.Command("git", arg...)
|
||||
str := executeCommand(cmd)
|
||||
str := wtf.ExecuteCommand(cmd)
|
||||
|
||||
data := strings.Split(str, "\n")
|
||||
|
||||
@@ -44,29 +44,9 @@ func (client *Client) ChangedFiles() []string {
|
||||
func (client *Client) Commits() []string {
|
||||
arg := []string{"log", "--date=format:\"%b %d, %Y\"", "-n 10", "--pretty=format:\"[forestgreen]%h [white]%s [grey]%an on %cd[white]\""}
|
||||
cmd := exec.Command("git", arg...)
|
||||
str := executeCommand(cmd)
|
||||
str := wtf.ExecuteCommand(cmd)
|
||||
|
||||
data := strings.Split(str, "\n")
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func executeCommand(cmd *exec.Cmd) string {
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return "err"
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return "err"
|
||||
}
|
||||
|
||||
var str string
|
||||
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||
str += string(b)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user