mirror of
https://github.com/docker/compose.git
synced 2026-09-01 07:11:06 +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
33
cli/main.go
33
cli/main.go
|
|
@ -32,12 +32,13 @@ import (
|
|||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/docker/api/cli/dockerclassic"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
|
@ -95,7 +96,7 @@ func main() {
|
|||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
runningOwnCommand = isOwnCommand(cmd)
|
||||
if !runningOwnCommand {
|
||||
execMoby(cmd.Context())
|
||||
dockerclassic.Exec(cmd.Context())
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
|
@ -119,7 +120,7 @@ func main() {
|
|||
root.SetHelpFunc(func(cmd *cobra.Command, args []string) {
|
||||
runningOwnCommand = isOwnCommand(cmd)
|
||||
if !runningOwnCommand {
|
||||
execMoby(cmd.Context())
|
||||
dockerclassic.Exec(cmd.Context())
|
||||
}
|
||||
helpFunc(cmd, args)
|
||||
})
|
||||
|
|
@ -161,7 +162,7 @@ func main() {
|
|||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
execMoby(ctx)
|
||||
dockerclassic.Exec(ctx)
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
@ -178,30 +179,6 @@ func newSigContext() (context.Context, func()) {
|
|||
return ctx, cancel
|
||||
}
|
||||
|
||||
func execMoby(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)
|
||||
}
|
||||
}
|
||||
|
||||
func determineCurrentContext(flag string, configDir string) (string, error) {
|
||||
res := flag
|
||||
if res == "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue