env.go 696 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package control
  2. import (
  3. "log"
  4. "os"
  5. "os/exec"
  6. "syscall"
  7. "github.com/codegangsta/cli"
  8. "github.com/rancherio/os/config"
  9. "github.com/rancherio/os/util"
  10. )
  11. func envAction(c *cli.Context) {
  12. cfg, err := config.LoadConfig()
  13. if err != nil {
  14. log.Fatal(err)
  15. }
  16. args := c.Args()
  17. osEnv := os.Environ()
  18. envMap := make(map[string]string, len(cfg.Environment)+len(osEnv))
  19. for k, v := range cfg.Environment {
  20. envMap[k] = v
  21. }
  22. for k, v := range util.KVPairs2Map(osEnv) {
  23. envMap[k] = v
  24. }
  25. if cmd, err := exec.LookPath(args[0]); err != nil {
  26. log.Fatal(err)
  27. } else {
  28. args[0] = cmd
  29. }
  30. if err := syscall.Exec(args[0], args, util.Map2KVPairs(envMap)); err != nil {
  31. log.Fatal(err)
  32. }
  33. }