[general] better failure result handling and method to list files
in current directory
This commit is contained in:
parent
2243d404a8
commit
f4272325e7
|
@ -2,6 +2,7 @@ package general
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -14,7 +15,9 @@ import (
|
||||||
func RunCommand(command string, values ...string) (result string, errCode int) {
|
func RunCommand(command string, values ...string) (result string, errCode int) {
|
||||||
cmd := exec.Command(command, values...)
|
cmd := exec.Command(command, values...)
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
|
var outErr bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
|
cmd.Stderr = &outErr
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
log.Fatalf("cmd.Start: %v", err)
|
log.Fatalf("cmd.Start: %v", err)
|
||||||
|
@ -24,6 +27,7 @@ func RunCommand(command string, values ...string) (result string, errCode int) {
|
||||||
if exiterr, ok := err.(*exec.ExitError); ok {
|
if exiterr, ok := err.(*exec.ExitError); ok {
|
||||||
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
|
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
|
||||||
errCode = status.ExitStatus()
|
errCode = status.ExitStatus()
|
||||||
|
result = outErr.String()
|
||||||
return result, errCode
|
return result, errCode
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -54,6 +58,15 @@ func GetChangedGoFiles() (result []string) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFilesFromDir returns a list of all files in the current directory
|
||||||
|
func GetFilesList() (result []string) {
|
||||||
|
files, _ := ioutil.ReadDir("./")
|
||||||
|
for _, f := range files {
|
||||||
|
result = append(result, f.Name())
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// GetGitRoot returns the path with the .git directory
|
// GetGitRoot returns the path with the .git directory
|
||||||
func GetGitRoot() string {
|
func GetGitRoot() string {
|
||||||
gitDir, _ := RunCommand("git", "rev-parse", "--git-dir")
|
gitDir, _ := RunCommand("git", "rev-parse", "--git-dir")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user