HandlersOK asserts that all commands have a handler. Without a handler, the command has no default behavior. Even for non-root commands (like 'groups' or 'users'), a handler is required. These handlers are likely just the 'help' handler, but this must be explicitly set.
(t *testing.T, cmd *serpent.Command)
| 12 | // These handlers are likely just the 'help' handler, but this must be |
| 13 | // explicitly set. |
| 14 | func HandlersOK(t *testing.T, cmd *serpent.Command) { |
| 15 | cmd.Walk(func(cmd *serpent.Command) { |
| 16 | if cmd.Handler == nil { |
| 17 | // If you see this error, make the Handler a helper invoker. |
| 18 | // Handler: func(inv *serpent.Invocation) error { |
| 19 | // return inv.Command.HelpHandler(inv) |
| 20 | // }, |
| 21 | t.Errorf("command %q has no handler, change to a helper invoker using: 'inv.Command.HelpHandler(inv)'", cmd.Name()) |
| 22 | } |
| 23 | }) |
| 24 | } |