diff --git a/app.go b/app.go index 3818010..43d816b 100644 --- a/app.go +++ b/app.go @@ -413,6 +413,10 @@ func (a *Application) setDefaults(context *ParseContext) error { if flag.name == "help" { return nil } + + if flag.name == "version" { + return nil + } flagElements[flag.name] = element } } diff --git a/app_test.go b/app_test.go index 3e35fe5..27c95e5 100644 --- a/app_test.go +++ b/app_test.go @@ -434,3 +434,14 @@ func TestCmdValidation(t *testing.T) { _, err = c.Parse([]string{"cmd", "--a", "A"}) assert.NoError(t, err) } + +func TestVersion(t *testing.T) { + c := newTestApp() + c.Flag("config", "path to config file").Default("config.yaml").ExistingFile() + c.Version("1.0.0") + + // the pre-action for version should be executed without running validation + // for ExistingFile + _, err := c.Parse([]string{"--version"}) + assert.NoError(t, err) +}