X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=cli.c;h=6bfb44ebd2b6b76b97462032aa453987e07a7030;hp=321b3fdfc82d6b924630e47111f2b1496db7b266;hb=62cdfc3d16f815e24b9c62eb9a3bacd9aa8f621a;hpb=7cd569acc8ecff9d75a722200b1a52d9d400edfc diff --git a/cli.c b/cli.c index 321b3fd..6bfb44e 100644 --- a/cli.c +++ b/cli.c @@ -1,3 +1,16 @@ +/* + * Copyright (C) 2011 Felix Fietkau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + #include #include @@ -6,6 +19,7 @@ static struct blob_buf b; static int timeout = 30; static bool simple_output = false; +static int verbose = 0; static const char *format_type(void *priv, struct blob_attr *attr) { @@ -13,6 +27,8 @@ static const char *format_type(void *priv, struct blob_attr *attr) [BLOBMSG_TYPE_INT8] = "\"Boolean\"", [BLOBMSG_TYPE_INT32] = "\"Integer\"", [BLOBMSG_TYPE_STRING] = "\"String\"", + [BLOBMSG_TYPE_ARRAY] = "\"Array\"", + [BLOBMSG_TYPE_TABLE] = "\"Table\"", }; const char *type = NULL; int typeid; @@ -35,7 +51,7 @@ static void receive_list_result(struct ubus_context *ctx, struct ubus_object_dat char *s; int rem; - if (simple_output) { + if (simple_output || !verbose) { printf("%s\n", obj->path); return; } @@ -46,7 +62,7 @@ static void receive_list_result(struct ubus_context *ctx, struct ubus_object_dat return; blob_for_each_attr(cur, obj->signature, rem) { - s = blobmsg_format_json_with_cb(cur, false, format_type, NULL); + s = blobmsg_format_json_with_cb(cur, false, format_type, NULL, -1); printf("\t%s\n", s); free(s); } @@ -58,7 +74,7 @@ static void receive_call_result_data(struct ubus_request *req, int type, struct if (!msg) return; - str = blobmsg_format_json(msg, true); + str = blobmsg_format_json_indent(msg, true, simple_output ? -1 : 0); printf("%s\n", str); free(str); } @@ -176,6 +192,7 @@ static int usage(const char *prog) " -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" + " -v: More verbose output\n" "\n" "Commands:\n" " - list [] List objects\n" @@ -207,7 +224,7 @@ int main(int argc, char **argv) progname = argv[0]; - while ((ch = getopt(argc, argv, "s:t:S")) != -1) { + while ((ch = getopt(argc, argv, "vs:t:S")) != -1) { switch (ch) { case 's': ubus_socket = optarg; @@ -218,6 +235,9 @@ int main(int argc, char **argv) case 'S': simple_output = true; break; + case 'v': + verbose++; + break; default: return usage(progname); }