Merge pull request #325 from docker/error_status_context_needs_login

Specific exit code when command fails because azure login is required
This commit is contained in:
Guillaume Tardif 2020-07-02 17:02:57 +02:00 committed by GitHub
commit ae76e0cf27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 3 deletions

View file

@ -27,6 +27,8 @@ import (
"syscall"
"time"
"github.com/docker/api/errdefs"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -174,15 +176,23 @@ func main() {
// Context should always be handled by new CLI
requiredCmd, _, _ := root.Find(os.Args[1:])
if requiredCmd != nil && isOwnCommand(requiredCmd) {
fatal(err)
exit(err)
}
mobycli.ExecIfDefaultCtxType(ctx)
checkIfUnknownCommandExistInDefaultContext(err, currentContext)
fatal(err)
exit(err)
}
}
func exit(err error) {
if errors.Is(err, errdefs.ErrLoginRequired) {
fmt.Fprintln(os.Stderr, fmt.Errorf("%v", err))
os.Exit(errdefs.ExitCodeLoginRequired)
}
fatal(err)
}
func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string) {
submatch := unknownCommandRegexp.FindSubmatch([]byte(err.Error()))
if len(submatch) == 2 {