зеркало из https://github.com/docker/compose.git
Call moby if the command is unknown
Will also check if the context is an original docker context
This commit is contained in:
Родитель
cdff00d571
Коммит
10bc4b93f6
10
cli/main.go
10
cli/main.go
|
@ -34,6 +34,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/api/cli/cmd"
|
||||
apicontext "github.com/docker/api/context"
|
||||
|
@ -73,8 +74,9 @@ func isContextCommand(cmd *cobra.Command) bool {
|
|||
func main() {
|
||||
var opts mainOpts
|
||||
root := &cobra.Command{
|
||||
Use: "docker",
|
||||
Long: "docker for the 2020s",
|
||||
Use: "docker",
|
||||
Long: "docker for the 2020s",
|
||||
SilenceErrors: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !isContextCommand(cmd) {
|
||||
execMoby(cmd.Context())
|
||||
|
@ -123,6 +125,10 @@ func main() {
|
|||
ctx = store.WithContextStore(ctx, s)
|
||||
|
||||
if err = root.ExecuteContext(ctx); err != nil {
|
||||
if strings.Contains(err.Error(), "unknown command") {
|
||||
execMoby(ctx)
|
||||
}
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ func ContextStore(ctx context.Context) Store {
|
|||
|
||||
// Store
|
||||
type Store interface {
|
||||
// Get returns the context with with name, it returns an error if the
|
||||
// context doesn't exist
|
||||
// Get returns the context with name, it returns an error if the context
|
||||
// doesn't exist
|
||||
Get(name string) (*Metadata, error)
|
||||
// Create creates a new context, it returns an error if a context with the
|
||||
// same name exists already.
|
||||
|
|
|
@ -29,7 +29,6 @@ package store
|
|||
|
||||
import (
|
||||
_ "crypto/sha256"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
@ -78,7 +77,6 @@ func TestGet(t *testing.T) {
|
|||
|
||||
m, ok := meta.Metadata.(TypeContext)
|
||||
assert.Equal(t, ok, true)
|
||||
fmt.Printf("%#v\n", meta)
|
||||
assert.Equal(t, "description", m.Description)
|
||||
assert.Equal(t, "type", m.Type)
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче