Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #641 from docker/fix_metrics_default_context
Browse files Browse the repository at this point in the history
In metrics, send context type, not context name (metrics for Moby calls)
  • Loading branch information
ndeloof authored Sep 23, 2020
2 parents 64cd8eb + 8302266 commit 91a668a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ $ docker context create %s <name>`, cc.Type(), store.EcsContextType), ctype)
}
mobycli.ExecIfDefaultCtxType(ctx, root)

checkIfUnknownCommandExistInDefaultContext(err, currentContext, root)
checkIfUnknownCommandExistInDefaultContext(err, currentContext, root, ctype)

exit(root, currentContext, err, ctype)
}
Expand Down Expand Up @@ -242,14 +242,14 @@ func fatal(err error) {
os.Exit(1)
}

func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string, root *cobra.Command) {
func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string, root *cobra.Command, contextType string) {
submatch := unknownCommandRegexp.FindSubmatch([]byte(err.Error()))
if len(submatch) == 2 {
dockerCommand := string(submatch[1])

if mobycli.IsDefaultContextCommand(dockerCommand) {
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)
metrics.Track(currentContext, os.Args[1:], root.PersistentFlags(), metrics.FailureStatus)
metrics.Track(contextType, os.Args[1:], root.PersistentFlags(), metrics.FailureStatus)
os.Exit(1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/mobycli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func Exec(root *cobra.Command) {
err := cmd.Run()
childExit <- true
if err != nil {
metrics.Track(store.DefaultContextName, os.Args[1:], root.PersistentFlags(), metrics.FailureStatus)
metrics.Track(store.DefaultContextType, os.Args[1:], root.PersistentFlags(), metrics.FailureStatus)

if exiterr, ok := err.(*exec.ExitError); ok {
os.Exit(exiterr.ExitCode())
}
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
metrics.Track(store.DefaultContextName, os.Args[1:], root.PersistentFlags(), metrics.SuccessStatus)
metrics.Track(store.DefaultContextType, os.Args[1:], root.PersistentFlags(), metrics.SuccessStatus)

os.Exit(0)
}
Expand Down

0 comments on commit 91a668a

Please sign in to comment.