summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Cather2025-08-29 18:34:59 +0000
committerFelix Fietkau2026-03-12 10:26:05 +0000
commit74f6277aabffc943d026f406df57c22595134c42 (patch)
treeeb77f015a365c1610aa829c19f1cfc8192fc6332
parentccc171953852676a3a4e9086408db117563b1437 (diff)
downloaduci-master.tar.gz
cli: in batch mode, print empty line if get failsHEADmaster
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 <mattbob4@gmail.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--cli.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/cli.c b/cli.c
index 36c21e4..e899387 100644
--- a/cli.c
+++ b/cli.c
@@ -476,6 +476,9 @@ static int uci_do_section_cmd(int cmd, int argc, char **argv)
return 255;
if (uci_lookup_ptr(ctx, &ptr, argv[1], true) != UCI_OK) {
+ if ((flags & CLI_FLAG_BATCH) && cmd == CMD_GET)
+ printf("\n");
+
cli_perror();
return 1;
}
@@ -488,6 +491,9 @@ static int uci_do_section_cmd(int cmd, int argc, char **argv)
switch(cmd) {
case CMD_GET:
if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
+ if (flags & CLI_FLAG_BATCH)
+ printf("\n");
+
ctx->err = UCI_ERR_NOTFOUND;
cli_perror();
return 1;