mirror of
https://github.com/rancher/os.git
synced 2025-09-01 23:04:41 +00:00
rancherctl env subcommand
Usage: rancherctl env <command> Executes <command> with environment from rancher.environment. Real env vars override those from rancher.environment.
This commit is contained in:
39
cmd/control/env.go
Normal file
39
cmd/control/env.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/rancherio/os/config"
|
||||
"github.com/rancherio/os/util"
|
||||
)
|
||||
|
||||
func envAction(c *cli.Context) {
|
||||
cfg, err := config.LoadConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
args := c.Args()
|
||||
osEnv := os.Environ()
|
||||
|
||||
envMap := make(map[string]string, len(cfg.Environment) + len(osEnv))
|
||||
for k, v := range cfg.Environment {
|
||||
envMap[k] = v
|
||||
}
|
||||
for k, v := range util.KVPairs2Map(osEnv) {
|
||||
envMap[k] = v
|
||||
}
|
||||
|
||||
if cmd, err := exec.LookPath(args[0]); err != nil {
|
||||
log.Fatal(err)
|
||||
} else {
|
||||
args[0] = cmd
|
||||
}
|
||||
if err := syscall.Exec(args[0], args, util.Map2KVPairs(envMap)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user