Skip to content

Commit 8dc5919

Browse files
committed
fix(display): don't run both root and regular actions on failure
It works in practice (until the test backend is merged) because the sole root action also terminates, so the doubling never occurs.
1 parent a23850d commit 8dc5919

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

display/threads/commands.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static char *find_target(char **);
4848
static bool parse(char **input_cursor, struct parse_result *result);
4949

5050
static char *call_action(struct ui_ctx *ctx, const struct command *c,
51-
const struct action_container *, size_t len, bool fail_loud);
51+
const struct action_container *, size_t len, bool *found);
5252

5353
static char *run(struct ui_ctx *, const struct command *);
5454

@@ -244,10 +244,12 @@ static bool parse(char **input_cursor, struct parse_result *result)
244244
}
245245

246246
static char *call_action(struct ui_ctx *ctx, const struct command *c,
247-
const struct action_container *candidates, size_t len, bool fail_loud)
247+
const struct action_container *candidates, size_t len, bool *found)
248248
{
249249
for (size_t i = 0; i < len; i++) {
250250
if (strcmp(c->action, candidates[i].name) == 0) {
251+
*found = true;
252+
251253
char *err_buf = candidates[i].hook(
252254
ctx, c->target_name, c->argc, c->argv);
253255

@@ -258,25 +260,27 @@ static char *call_action(struct ui_ctx *ctx, const struct command *c,
258260
}
259261
}
260262

261-
if (fail_loud) {
262-
char *ret = malloc(512);
263-
snprintf(ret, 512, "no such action found: %s", c->action);
264-
return ret;
265-
} else
266-
return NULL;
263+
*found = false;
264+
265+
char *ret = malloc(512);
266+
snprintf(ret, 512, "no such action found: %s", c->action);
267+
return ret;
267268
}
268269

269270
static char *run(struct ui_ctx *ctx, const struct command *c)
270271
{
271272
char *ret = NULL;
273+
bool found;
274+
272275
if (strcmp(c->target_name, "root") == 0) {
273-
if ((ret = call_action(ctx, c, root_actions,
274-
sizeof(root_actions) / sizeof(*root_actions), false)))
275-
return ret;
276+
char *root_ret = call_action(ctx, c, root_actions,
277+
sizeof(root_actions) / sizeof(*root_actions), &found);
278+
if (found)
279+
return root_ret;
276280
}
277281

278282
ret = call_action(
279-
ctx, c, actions, sizeof(actions) / sizeof(*actions), true);
283+
ctx, c, actions, sizeof(actions) / sizeof(*actions), &found);
280284
return ret;
281285
}
282286

0 commit comments

Comments
 (0)