|
@@ -9,16 +9,42 @@ import (
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+func init() {
|
|
|
|
+ runnable = cmd{}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// logger component for printing status messages to stderr
|
|
|
|
+type logger interface {
|
|
|
|
+ Debug(string, ...interface{})
|
|
|
|
+ Error(string, ...interface{})
|
|
|
|
+ Info(string, ...interface{})
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var stat = os.Stat
|
|
|
|
+var isNotExist = os.IsNotExist
|
|
|
|
+
|
|
|
|
+type runner interface {
|
|
|
|
+ Run(string, ...string) ([]byte, error)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var runnable runner
|
|
|
|
+
|
|
|
|
+type cmd struct{}
|
|
|
|
+
|
|
|
|
+func (self cmd) Run(command string, args ...string) ([]byte, error) {
|
|
|
|
+ return exec.Command(command, args...).Output()
|
|
|
|
+}
|
|
|
|
+
|
|
// check that a path exists
|
|
// check that a path exists
|
|
// does not care if it is a directory
|
|
// does not care if it is a directory
|
|
// will not say whether user has rw access, but
|
|
// will not say whether user has rw access, but
|
|
// will throw an error if the user cannot read the parent directory
|
|
// will throw an error if the user cannot read the parent directory
|
|
func exists(path string) (bool, error) {
|
|
func exists(path string) (bool, error) {
|
|
- _, err := os.Stat(path)
|
|
|
|
|
|
+ _, err := stat(path)
|
|
if err == nil {
|
|
if err == nil {
|
|
return true, nil
|
|
return true, nil
|
|
}
|
|
}
|
|
- if os.IsNotExist(err) {
|
|
|
|
|
|
+ if isNotExist(err) {
|
|
return false, nil
|
|
return false, nil
|
|
}
|
|
}
|
|
return false, err
|
|
return false, err
|
|
@@ -26,9 +52,9 @@ func exists(path string) (bool, error) {
|
|
|
|
|
|
// if within a git repo, gets git version as a short-hash
|
|
// if within a git repo, gets git version as a short-hash
|
|
// otherwise falls back to a unix timestamp
|
|
// otherwise falls back to a unix timestamp
|
|
-func version() string {
|
|
|
|
|
|
+func version(dir string) string {
|
|
version := strconv.FormatInt(time.Now().Unix(), 10)
|
|
version := strconv.FormatInt(time.Now().Unix(), 10)
|
|
- out, err := exec.Command("sh", "-c", "git rev-parse --short HEAD").Output()
|
|
|
|
|
|
+ out, err := runnable.Run("sh", "-c", "git", "-C", dir, "rev-parse", "--short", "HEAD")
|
|
if err == nil {
|
|
if err == nil {
|
|
version = strings.Trim(string(out), "\n")
|
|
version = strings.Trim(string(out), "\n")
|
|
}
|
|
}
|
|
@@ -39,9 +65,3 @@ func version() string {
|
|
func basename(name string) string {
|
|
func basename(name string) string {
|
|
return filepath.Base(strings.TrimSuffix(name, filepath.Ext(name)))
|
|
return filepath.Base(strings.TrimSuffix(name, filepath.Ext(name)))
|
|
}
|
|
}
|
|
-
|
|
|
|
-type logger interface {
|
|
|
|
- Debug(string, ...interface{})
|
|
|
|
- Error(string, ...interface{})
|
|
|
|
- Info(string, ...interface{})
|
|
|
|
-}
|
|
|