Skip to content
quarry Artifact [50df6f5bb3]
Login

Artifact [50df6f5bb3]

Artifact 50df6f5bb3255ea351dc4ad2f185fb5ca535f49430bd47fc625cca3562af088f:


package main

import (
	"errors"
	"fmt"
	"os"
	"path/filepath"

	"craftdesign.group/quarry/internal/runner/install"
)

// runnerExit reports a runner command's error and ends the program:
// with the code an ExitError carries (doctor's 1, 3 and 2), else 1.
func runnerExit(prog string, err error) {
	var ee *install.ExitError
	if errors.As(err, &ee) {
		if ee.Msg != "" {
			fmt.Fprintln(os.Stderr, prog+":", ee.Msg)
		}
		os.Exit(ee.Code)
	}
	fmt.Fprintln(os.Stderr, prog+":", err)
	os.Exit(1)
}

// isRunnerCopy is whether this program was started under the name
// quarry-runner: install copies the running binary there, so a runner
// installed from `quarry runner install` runs as the runner it is.
func isRunnerCopy() bool {
	return len(os.Args) > 0 && filepath.Base(os.Args[0]) == "quarry-runner"
}