param: abstract 'struct command' so param doesn't need to access it.

I want to use param functions in plugins, and they don't have struct
command.

I had to use a special arg to param() for check to flag it as allowing
extra parameters, rather than adding a one-use accessor.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-12-08 11:09:25 +10:30
parent 061938068f
commit 3f16c9a665
7 changed files with 83 additions and 23 deletions

24
common/json_command.h Normal file
View File

@@ -0,0 +1,24 @@
/* These functions must be supplied by any binary linking with common/param
* so it can fail commands. */
#ifndef LIGHTNING_COMMON_JSON_COMMAND_H
#define LIGHTNING_COMMON_JSON_COMMAND_H
#include "config.h"
#include <ccan/compiler/compiler.h>
#include <stdbool.h>
struct command;
/* Caller supplied this: param assumes it can call it. */
void PRINTF_FMT(3, 4) command_fail(struct command *cmd, int code,
const char *fmt, ...);
/* Also caller supplied: is this invoked simply to get usage? */
bool command_usage_only(const struct command *cmd);
/* If so, this is called. */
void command_set_usage(struct command *cmd, const char *usage);
/* Also caller supplied: is this invoked simply to check parameters? */
bool command_check_only(const struct command *cmd);
#endif /* LIGHTNING_COMMON_JSON_COMMAND_H */