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

View File

@@ -48,6 +48,21 @@ bool json_feerate_estimate(struct command *cmd UNNEEDED,
{ fprintf(stderr, "json_feerate_estimate called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
void command_set_usage(struct command *cmd, const char *usage)
{
cmd->usage = usage;
}
bool command_usage_only(const struct command *cmd)
{
return cmd->mode == CMD_USAGE;
}
bool command_check_only(const struct command *cmd)
{
return cmd->mode == CMD_CHECK;
}
struct json {
jsmntok_t *toks;
char *buffer;
@@ -353,7 +368,7 @@ static void five_hundred_params(void)
/* first test object version */
struct json *j = json_parse(params, obj);
assert(param_arr(cmd, j->buffer, j->toks, params));
assert(param_arr(cmd, j->buffer, j->toks, params, false));
for (int i = 0; i < tal_count(ints); ++i) {
assert(ints[i]);
assert(*ints[i] == i);
@@ -362,7 +377,7 @@ static void five_hundred_params(void)
/* now test array */
j = json_parse(params, arr);
assert(param_arr(cmd, j->buffer, j->toks, params));
assert(param_arr(cmd, j->buffer, j->toks, params, false));
for (int i = 0; i < tal_count(ints); ++i) {
assert(*ints[i] == i);
}
@@ -563,7 +578,6 @@ int main(void)
setup_tmpctx();
cmd = tal(tmpctx, struct command);
cmd->mode = CMD_NORMAL;
cmd->allow_unused = false;
fail_msg = tal_arr(cmd, char, 10000);
zero_params();