shellOutput runs cmd with args, captures stdout, and returns it stripped of trailing whitespace. Returns empty on error: for example, when the command is missing (git absent) or the working directory lacks a git repo. Used by the derived Vars whose defaults are git metadata.
(cmd string, args ...string)
| 45 | // command is missing (git absent) or the working directory lacks a git |
| 46 | // repo. Used by the derived Vars whose defaults are git metadata. |
| 47 | func shellOutput(cmd string, args ...string) string { |
| 48 | out, err := exec.Command(cmd, args...).Output() |
| 49 | if err != nil { |
| 50 | return "" |
| 51 | } |
| 52 | return strings.TrimSpace(string(out)) |
| 53 | } |
| 54 | |
| 55 | // Var is a single build-configuration environment variable. It bundles |
| 56 | // the env-var name (Name) with a defaulter: either a literal fall-through |