From fb1bfeb8f5bcbf3b66036041c6d953fd34777314 Mon Sep 17 00:00:00 2001 From: Cory Bennett Date: Fri, 1 Sep 2017 23:30:59 -0700 Subject: [PATCH] use jiracli.Error object to disambiguate between kingpin errors and cli errors --- cmd/jira/main.go | 15 ++++++++++----- jiracli/error.go | 13 +++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 jiracli/error.go diff --git a/cmd/jira/main.go b/cmd/jira/main.go index a11e5fa..47e4062 100644 --- a/cmd/jira/main.go +++ b/cmd/jira/main.go @@ -329,11 +329,16 @@ func main() { } } if _, err := app.Parse(os.Args[1:]); err != nil { - ctx, _ := app.ParseContext(os.Args[1:]) - if ctx != nil { - app.UsageForContext(ctx) + if _, ok := err.(*jiracli.Error); ok { + log.Errorf("%s", err) + panic(jiracli.Exit{Code: 1}) + } else { + ctx, _ := app.ParseContext(os.Args[1:]) + if ctx != nil { + app.UsageForContext(ctx) + } + log.Errorf("Invalid Usage: %s", err) + panic(jiracli.Exit{Code: 1}) } - log.Errorf("Invalid Usage: %s", err) - panic(jiracli.Exit{Code: 1}) } } diff --git a/jiracli/error.go b/jiracli/error.go new file mode 100644 index 0000000..74dd1eb --- /dev/null +++ b/jiracli/error.go @@ -0,0 +1,13 @@ +package jiracli + +import "github.com/pkg/errors" + +type Error struct { + error +} + +func cliError(cause error) error { + return &Error{ + errors.WithStack(cause), + } +}