You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
872 B

package main
import (
"os"
"os/exec"
"gopkg.in/alecthomas/kingpin.v2"
common "source.heropunch.io/tomo/go-coreutils"
)
func main() {
app := kingpin.New("env", "modify the environment, then print it or run a command")
ignoreEnv := kingpin.Flag(
"ignore-environment",
"Completely ignore the existing environment and execute cmd only with each (var, value) tuple specified.",
).Short('i').Bool()
unset := kingpin.Flag("unset", "Unset var in the environment.").PlaceHolder("var").Short('u').Strings()
cmd := kingpin.Arg("cmd", "").String()
args := kingpin.Arg("args", "").Strings()
kingpin.Parse()
for _, key := range *unset {
os.Unsetenv(key)
}
if *ignoreEnv {
os.Clearenv()
}
if *cmd == "" {
common.PrintEnv()
os.Exit(0)
}
command := exec.Command(*cmd, *args...)
err := command.Run()
app.FatalIfError(err, "error running command:")
}