From 6facb814094c0138cbaae954d071660d55f8243d Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 27 Mar 2011 17:40:46 +0200 Subject: [PATCH] improve output for scripts --- cli.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cli.c b/cli.c index be8ba23..ef1b893 100644 --- a/cli.c +++ b/cli.c @@ -5,6 +5,7 @@ static struct blob_buf b; static int timeout = 30; +static bool simple_output = false; static const char *format_type(void *priv, struct blob_attr *attr) { @@ -34,6 +35,11 @@ static void receive_list_result(struct ubus_context *ctx, struct ubus_object_dat char *s; int rem; + if (simple_output) { + printf("%s\n", obj->path); + return; + } + printf("'%s' @%08x\n", obj->path, obj->id); if (!obj->signature) @@ -63,7 +69,7 @@ static void receive_event(struct ubus_context *ctx, struct ubus_event_handler *e char *str; str = blobmsg_format_json(msg, true); - printf("\"%s\": %s\n", type, str); + printf("{ \"%s\": %s }\n", type, str); free(str); } @@ -165,6 +171,8 @@ static int usage(const char *prog) "Usage: %s [] [arguments...]\n" "Options:\n" " -s : Set the unix domain socket to connect to\n" + " -t : Set the timeout (in seconds) for a command to complete\n" + " -S: Use simplified output (for scripts)\n" "\n" "Commands:\n" " - list [] List objects\n" @@ -196,7 +204,7 @@ int main(int argc, char **argv) progname = argv[0]; - while ((ch = getopt(argc, argv, "s:t:")) != -1) { + while ((ch = getopt(argc, argv, "s:t:S")) != -1) { switch (ch) { case 's': ubus_socket = optarg; @@ -204,6 +212,9 @@ int main(int argc, char **argv) case 't': timeout = atoi(optarg); break; + case 'S': + simple_output = true; + break; default: return usage(progname); } -- 2.11.0