Call moby if the command is unknown

Will also check if the context is an original docker context
This commit is contained in:
Djordje Lukic 2020-04-27 11:32:16 +02:00
Родитель cdff00d571
Коммит 10bc4b93f6
3 изменённых файлов: 10 добавлений и 6 удалений

Просмотреть файл

@ -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)
})