diff --git a/app_test.go b/app_test.go index 0b9e154..51a2d4c 100644 --- a/app_test.go +++ b/app_test.go @@ -2,7 +2,7 @@ package cli_test import ( "fmt" - "github.com/codegangsta/cli" + "." "os" "testing" ) @@ -347,6 +347,26 @@ func TestAppHelpPrinter(t *testing.T) { } } +func TestAppVersionPrinter(t *testing.T) { + oldPrinter := cli.VersionPrinter + defer func() { + cli.VersionPrinter = oldPrinter + }() + + var wasCalled = false + cli.VersionPrinter = func(c *cli.Context) { + wasCalled = true + } + + app := cli.NewApp() + ctx := cli.NewContext(app, nil, nil) + cli.ShowVersion(ctx) + + if wasCalled == false { + t.Errorf("Version printer expected to be called, but was not") + } +} + func TestAppCommandNotFound(t *testing.T) { beforeRun, subcommandRun := false, false app := cli.NewApp() diff --git a/help.go b/help.go index 7c04005..45b9db8 100644 --- a/help.go +++ b/help.go @@ -92,6 +92,9 @@ var helpSubcommand = Command{ // Prints help for the App var HelpPrinter = printHelp +// Prints version for the App +var VersionPrinter = printVersion + func ShowAppHelp(c *Context) { HelpPrinter(AppHelpTemplate, c.App) } @@ -129,6 +132,10 @@ func ShowSubcommandHelp(c *Context) { // Prints the version number of the App func ShowVersion(c *Context) { + VersionPrinter(c) +} + +func printVersion(c *Context) { fmt.Printf("%v version %v\n", c.App.Name, c.App.Version) }