Merge pull request #568 from kklipsch/master
Fix for #556 broke the api for users who were using the ActionFunc
This commit is contained in:
commit
3ba36a3127
4
app.go
4
app.go
@ -479,7 +479,9 @@ func (a Author) String() string {
|
|||||||
// it's an ActionFunc or a func with the legacy signature for Action, the func
|
// it's an ActionFunc or a func with the legacy signature for Action, the func
|
||||||
// is run!
|
// is run!
|
||||||
func HandleAction(action interface{}, context *Context) (err error) {
|
func HandleAction(action interface{}, context *Context) (err error) {
|
||||||
if a, ok := action.(func(*Context) error); ok {
|
if a, ok := action.(ActionFunc); ok {
|
||||||
|
return a(context)
|
||||||
|
} else if a, ok := action.(func(*Context) error); ok {
|
||||||
return a(context)
|
return a(context)
|
||||||
} else if a, ok := action.(func(*Context)); ok { // deprecated function signature
|
} else if a, ok := action.(func(*Context)); ok { // deprecated function signature
|
||||||
a(context)
|
a(context)
|
||||||
|
19
app_test.go
19
app_test.go
@ -1664,3 +1664,22 @@ func TestShellCompletionForIncompleteFlags(t *testing.T) {
|
|||||||
t.Errorf("app should not return an error: %s", err)
|
t.Errorf("app should not return an error: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHandleActionActuallyWorksWithActions(t *testing.T) {
|
||||||
|
var f ActionFunc
|
||||||
|
called := false
|
||||||
|
f = func(c *Context) error {
|
||||||
|
called = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err := HandleAction(f, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Should not have errored: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !called {
|
||||||
|
t.Errorf("Function was not called")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user