exec.go 827 B

123456789101112131415161718192021222324252627282930313233343536
  1. package dockerclassic
  2. import (
  3. "context"
  4. "fmt"
  5. "os"
  6. "os/exec"
  7. apicontext "github.com/docker/api/context"
  8. "github.com/docker/api/context/store"
  9. )
  10. // Exec will delegate the cli command to docker-classic
  11. func Exec(ctx context.Context) {
  12. currentContext := apicontext.CurrentContext(ctx)
  13. s := store.ContextStore(ctx)
  14. _, err := s.Get(currentContext)
  15. // Only run original docker command if the current context is not
  16. // ours.
  17. if err != nil {
  18. cmd := exec.CommandContext(ctx, "docker-classic", os.Args[1:]...)
  19. cmd.Stdin = os.Stdin
  20. cmd.Stdout = os.Stdout
  21. cmd.Stderr = os.Stderr
  22. if err := cmd.Run(); err != nil {
  23. if exiterr, ok := err.(*exec.ExitError); ok {
  24. fmt.Fprintln(os.Stderr, exiterr.Error())
  25. os.Exit(exiterr.ExitCode())
  26. }
  27. fmt.Fprintln(os.Stderr, err)
  28. os.Exit(1)
  29. }
  30. os.Exit(0)
  31. }
  32. }