From 449f261ee9faccc374c97ed04bb58def80ac34ed Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sun, 13 Jul 2014 17:26:20 +0100 Subject: [PATCH] Add App.RunAndExitOnError shortcut --- app.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app.go b/app.go index 9ba043e..2f4bd34 100644 --- a/app.go +++ b/app.go @@ -131,6 +131,14 @@ func (a *App) Run(arguments []string) error { return nil } +// Another entry point to the cli app, takes care of passing arguments and error handling +func (a *App) RunAndExitOnError() { + if err := a.Run(os.Args); err != nil { + os.Stderr.WriteString(fmt.Sprintln(err)) + os.Exit(1) + } +} + // Invokes the subcommand given the context, parses ctx.Args() to generate command-specific flags func (a *App) RunAsSubcommand(ctx *Context) error { // append help to commands