|
@@ -60,6 +60,7 @@ var (
|
|
|
"serve": {},
|
|
"serve": {},
|
|
|
"version": {},
|
|
"version": {},
|
|
|
}
|
|
}
|
|
|
|
|
+ unknownCommandRegexp = regexp.MustCompile(`unknown command "([^"]*)"`)
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
@@ -140,11 +141,9 @@ func main() {
|
|
|
ctx, cancel := newSigContext()
|
|
ctx, cancel := newSigContext()
|
|
|
defer cancel()
|
|
defer cancel()
|
|
|
|
|
|
|
|
- if opts.Host != "" {
|
|
|
|
|
- mobycli.ExecRegardlessContext(ctx)
|
|
|
|
|
- }
|
|
|
|
|
- if opts.Version {
|
|
|
|
|
- mobycli.ExecRegardlessContext(ctx)
|
|
|
|
|
|
|
+ // --host and --version should immediately be forwarded to the original cli
|
|
|
|
|
+ if opts.Host != "" || opts.Version {
|
|
|
|
|
+ mobycli.Exec(ctx)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if opts.Config == "" {
|
|
if opts.Config == "" {
|
|
@@ -171,30 +170,26 @@ func main() {
|
|
|
ctx = apicontext.WithCurrentContext(ctx, currentContext)
|
|
ctx = apicontext.WithCurrentContext(ctx, currentContext)
|
|
|
ctx = store.WithContextStore(ctx, s)
|
|
ctx = store.WithContextStore(ctx, s)
|
|
|
|
|
|
|
|
- err = root.ExecuteContext(ctx)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
|
|
+ if err = root.ExecuteContext(ctx); err != nil {
|
|
|
// Context should always be handled by new CLI
|
|
// Context should always be handled by new CLI
|
|
|
requiredCmd, _, _ := root.Find(os.Args[1:])
|
|
requiredCmd, _, _ := root.Find(os.Args[1:])
|
|
|
if requiredCmd != nil && isOwnCommand(requiredCmd) {
|
|
if requiredCmd != nil && isOwnCommand(requiredCmd) {
|
|
|
- fmt.Fprintln(os.Stderr, err)
|
|
|
|
|
- os.Exit(1)
|
|
|
|
|
|
|
+ fatal(err)
|
|
|
}
|
|
}
|
|
|
mobycli.ExecIfDefaultCtxType(ctx)
|
|
mobycli.ExecIfDefaultCtxType(ctx)
|
|
|
|
|
|
|
|
checkIfUnknownCommandExistInDefaultContext(err, currentContext)
|
|
checkIfUnknownCommandExistInDefaultContext(err, currentContext)
|
|
|
- fmt.Fprintln(os.Stderr, err)
|
|
|
|
|
- os.Exit(1)
|
|
|
|
|
|
|
+ fatal(err)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string) {
|
|
func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string) {
|
|
|
- re := regexp.MustCompile(`unknown command "([^"]*)"`)
|
|
|
|
|
- submatch := re.FindSubmatch([]byte(err.Error()))
|
|
|
|
|
|
|
+ submatch := unknownCommandRegexp.FindSubmatch([]byte(err.Error()))
|
|
|
if len(submatch) == 2 {
|
|
if len(submatch) == 2 {
|
|
|
dockerCommand := string(submatch[1])
|
|
dockerCommand := string(submatch[1])
|
|
|
|
|
|
|
|
if mobycli.IsDefaultContextCommand(dockerCommand) {
|
|
if mobycli.IsDefaultContextCommand(dockerCommand) {
|
|
|
- fmt.Fprintf(os.Stderr, "Command \"%s\" not available in current context (%s), you can use the \"default\" context to run this command\n", dockerCommand, currentContext)
|
|
|
|
|
|
|
+ fmt.Fprintf(os.Stderr, "Command %q not available in current context (%s), you can use the \"default\" context to run this command\n", dockerCommand, currentContext)
|
|
|
os.Exit(1)
|
|
os.Exit(1)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|