diff options
| author | Christine Dodrill <me@christine.website> | 2018-10-05 14:03:55 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2018-10-05 14:31:22 -0700 |
| commit | c63e73391d634bdb25b3df1c582bb56b6d9a0963 (patch) | |
| tree | 81ec642a36c4ca84b3d0d4dfd8d2a91d09f762cd /internal/internal.go | |
| parent | dbeba1e5c5c0bc534a515eb298ee4f1d49df4d20 (diff) | |
| download | x-c63e73391d634bdb25b3df1c582bb56b6d9a0963.tar.xz x-c63e73391d634bdb25b3df1c582bb56b6d9a0963.zip | |
mastodon/sona-pi-toki-pona: build and deploy in go, not shell
Diffstat (limited to 'internal/internal.go')
| -rw-r--r-- | internal/internal.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/internal.go b/internal/internal.go index f21624e..9c36aa3 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -1,17 +1,36 @@ package internal import ( + "context" "encoding/json" "flag" "fmt" "log" "net/http" "os" + "os/exec" + "time" "github.com/Xe/x/tools/license/licenses" "go4.org/legal" ) +// current working directory and date:time tag of app boot (useful for tagging slugs) +var ( + WD string + DateTag string +) + +func init() { + lwd, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + + WD = lwd + DateTag = time.Now().Format("010220061504") +} + var ( licenseShow = flag.Bool("license", false, "show software license?") ) @@ -38,3 +57,24 @@ func HandleLicense() { os.Exit(0) } } + +// ShouldWork explodes if the given command with the given env, working dir and context fails. +func ShouldWork(ctx context.Context, env []string, dir string, cmdName string, args ...string) { + loc, err := exec.LookPath(cmdName) + if err != nil { + log.Fatal(err) + } + + cmd := exec.CommandContext(ctx, loc, args...) + cmd.Dir = dir + cmd.Env = env + + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + log.Printf("starting process, env: %v, pwd: %s, cmd: %s, args: %v", env, dir, loc, args) + err = cmd.Run() + if err != nil { + log.Fatal(err) + } +} |
