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:") }