mirror of
https://github.com/docker/compose.git
synced 2026-08-28 12:23:49 +00:00
Add docker context inspect command relying on classic docker
This commit is contained in:
parent
832651b1dc
commit
528d47ce08
5 changed files with 96 additions and 28 deletions
36
cli/dockerclassic/exec.go
Normal file
36
cli/dockerclassic/exec.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package dockerclassic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
apicontext "github.com/docker/api/context"
|
||||
"github.com/docker/api/context/store"
|
||||
)
|
||||
|
||||
// Exec will delegate the cli command to docker-classic
|
||||
func Exec(ctx context.Context) {
|
||||
currentContext := apicontext.CurrentContext(ctx)
|
||||
s := store.ContextStore(ctx)
|
||||
|
||||
_, err := s.Get(currentContext)
|
||||
// Only run original docker command if the current context is not
|
||||
// ours.
|
||||
if err != nil {
|
||||
cmd := exec.CommandContext(ctx, "docker-classic", os.Args[1:]...)
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
if exiterr, ok := err.(*exec.ExitError); ok {
|
||||
fmt.Fprintln(os.Stderr, exiterr.Error())
|
||||
os.Exit(exiterr.ExitCode())
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue