improve output for scripts
authorFelix Fietkau <nbd@openwrt.org>
Sun, 27 Mar 2011 15:40:46 +0000 (17:40 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 27 Mar 2011 15:41:33 +0000 (17:41 +0200)
cli.c

diff --git a/cli.c b/cli.c
index be8ba23df9bb4bc8fec3354f3b19ebd2c5a8a3a3..ef1b8931893443880d55203ddc21a9c451824b0d 100644 (file)
--- 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 [<options>] <command> [arguments...]\n"
                "Options:\n"
                " -s <socket>:          Set the unix domain socket to connect to\n"
+               " -t <timeout>:         Set the timeout (in seconds) for a command to complete\n"
+               " -S:                   Use simplified output (for scripts)\n"
                "\n"
                "Commands:\n"
                " - list [<path>]                       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);
                }