param: make command sinks (fail/success) return a special type.

These routines free the 'struct command': a common coding error is not
to return immediately.

To catch this, we make them return a non-NULL 'struct command_result
*', and we're going to make the command handlers return the same (to
encourage 'return command_fail(...)'-style usage).

We also provide two sources for external use:
1. command_param_failed() when param() fails.
2. command_its_complicated() for some complex cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-12-16 15:19:06 +10:30
parent 12731c4a60
commit 93bf7c4839
6 changed files with 90 additions and 25 deletions

View File

@@ -7,10 +7,12 @@
#include <stdbool.h>
struct command;
struct command_result;
/* Caller supplied this: param assumes it can call it. */
void PRINTF_FMT(3, 4) command_fail(struct command *cmd, int code,
const char *fmt, ...);
struct command_result *command_fail(struct command *cmd, int code,
const char *fmt, ...)
PRINTF_FMT(3, 4);
/* Also caller supplied: is this invoked simply to get usage? */
bool command_usage_only(const struct command *cmd);