Skip to content

Commit 74f6277

Browse files
MattCatznbd168
authored andcommitted
cli: in batch mode, print empty line if get fails
Currently get commands return nothing to stdout on error in batch mode. In practice, this makes them hard to use in scripts. If the caller sends 4 gets and we only return 3 lines, the caller can not easily determine which one did not work. This changes the get command behavior in batch mode to always print a new line, even on error. This allows the caller to determine which get did not work. e.x. if the 3rd line is blank then the 3rd get did not work. Signed-off-by: Matthew Cather <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
1 parent ccc1719 commit 74f6277

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

cli.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ static int uci_do_section_cmd(int cmd, int argc, char **argv)
476476
return 255;
477477

478478
if (uci_lookup_ptr(ctx, &ptr, argv[1], true) != UCI_OK) {
479+
if ((flags & CLI_FLAG_BATCH) && cmd == CMD_GET)
480+
printf("\n");
481+
479482
cli_perror();
480483
return 1;
481484
}
@@ -488,6 +491,9 @@ static int uci_do_section_cmd(int cmd, int argc, char **argv)
488491
switch(cmd) {
489492
case CMD_GET:
490493
if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
494+
if (flags & CLI_FLAG_BATCH)
495+
printf("\n");
496+
491497
ctx->err = UCI_ERR_NOTFOUND;
492498
cli_perror();
493499
return 1;

0 commit comments

Comments
 (0)