From 8e6aa34a1284bc29e84866ed015bca0f3dd2d88e Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Sun, 21 Aug 2016 13:51:55 -0700 Subject: [PATCH 1/2] remove the possiblity of end-user's seeing deprecation warnings Instead use deprecation pattern described in https://blog.golang.org/godoc-documenting-go-code. Fixes #507 --- app.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app.go b/app.go index 0755bb6..3b54518 100644 --- a/app.go +++ b/app.go @@ -62,10 +62,11 @@ type App struct { // An action to execute after any subcommands are run, but after the subcommand has finished // It is run even if Action() panics After AfterFunc + // The action to execute when no subcommands are specified + // Expects a `cli.ActionFunc` but will accept the *deprecated* signature of `func(*cli.Context) {}` + // *Note*: support for the deprecated `Action` signature will be removed in a future version Action interface{} - // TODO: replace `Action: interface{}` with `Action: ActionFunc` once some kind - // of deprecation period has passed, maybe? // Execute this function if the proper command cannot be found CommandNotFound CommandNotFoundFunc @@ -247,11 +248,12 @@ func (a *App) Run(arguments []string) (err error) { return err } -// DEPRECATED: Another entry point to the cli app, takes care of passing arguments and error handling +// RunAndExitOnError calls .Run() and exits non-zero if an error was returned +// +// Deprecated: instead you should return an error that fulfills cli.ExitCoder +// to cli.App.Run. This will cause the application to exit with the given eror +// code in the cli.ExitCoder func (a *App) RunAndExitOnError() { - fmt.Fprintf(a.errWriter(), - "DEPRECATED cli.App.RunAndExitOnError. %s See %s\n", - contactSysadmin, runAndExitOnErrorDeprecationURL) if err := a.Run(os.Args); err != nil { fmt.Fprintln(a.errWriter(), err) OsExiter(1) @@ -471,7 +473,7 @@ func HandleAction(action interface{}, context *Context) (err error) { // swallowing all panics that may happen when calling an Action func. s := fmt.Sprintf("%v", r) if strings.HasPrefix(s, "reflect: ") && strings.Contains(s, "too many input arguments") { - err = NewExitError(fmt.Sprintf("ERROR unknown Action error: %v. See %s", r, appActionDeprecationURL), 2) + err = NewExitError(fmt.Sprintf("ERROR unknown Action error: %v."), 2) } else { panic(r) } @@ -485,9 +487,6 @@ func HandleAction(action interface{}, context *Context) (err error) { vals := reflect.ValueOf(action).Call([]reflect.Value{reflect.ValueOf(context)}) if len(vals) == 0 { - fmt.Fprintf(ErrWriter, - "DEPRECATED Action signature. Must be `cli.ActionFunc`. %s See %s\n", - contactSysadmin, appActionDeprecationURL) return nil } From a5ca09a9344c444c8dfcd5c1718d06b75b7aac1e Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Sun, 21 Aug 2016 14:06:59 -0700 Subject: [PATCH 2/2] fixup! remove the possiblity of end-user's seeing deprecation warnings --- app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.go b/app.go index 3b54518..b9adf46 100644 --- a/app.go +++ b/app.go @@ -473,7 +473,7 @@ func HandleAction(action interface{}, context *Context) (err error) { // swallowing all panics that may happen when calling an Action func. s := fmt.Sprintf("%v", r) if strings.HasPrefix(s, "reflect: ") && strings.Contains(s, "too many input arguments") { - err = NewExitError(fmt.Sprintf("ERROR unknown Action error: %v."), 2) + err = NewExitError(fmt.Sprintf("ERROR unknown Action error: %v.", r), 2) } else { panic(r) }