From 58bfabca6d42352c357788aa392ccd2c04f673e8 Mon Sep 17 00:00:00 2001 From: Tim Jarratt Date: Tue, 4 Feb 2014 08:40:06 -0800 Subject: [PATCH] Add a way to override the app help printer Fixes #64 --- app_test.go | 19 +++++++++++++++++++ help.go | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app_test.go b/app_test.go index 50f263383c..f329b91361 100644 --- a/app_test.go +++ b/app_test.go @@ -225,3 +225,22 @@ func TestApp_BeforeFunc(t *testing.T) { } } + +func TestAppHelpPrinter(t *testing.T) { + oldPrinter := cli.HelpPrinter + defer func() { + cli.HelpPrinter = oldPrinter + }() + + var wasCalled = false + cli.HelpPrinter = func(template string, data interface{}) { + wasCalled = true + } + + app := cli.NewApp() + app.Run([]string{"-h"}) + + if wasCalled == false { + t.Errorf("Help printer expected to be called, but was not") + } +} diff --git a/help.go b/help.go index 41b58afbb6..094d01d7f4 100644 --- a/help.go +++ b/help.go @@ -59,8 +59,9 @@ var helpCommand = Command{ } // Prints help for the App +var HelpPrinter = printHelp func ShowAppHelp(c *Context) { - printHelp(AppHelpTemplate, c.App) + HelpPrinter(AppHelpTemplate, c.App) } // Prints help for the given command