mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 00:54:20 +01:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user