+static int ubus_cli_send(struct ubus_context *ctx, int argc, char **argv)
+{
+ if (argc < 1 || argc > 2)
+ return -2;
+
+ blob_buf_init(&b, 0);
+
+ if (argc == 2 && !blobmsg_add_json_from_string(&b, argv[1])) {
+ fprintf(stderr, "Failed to parse message data\n");
+ return -1;
+ }
+
+ return ubus_send_event(ctx, argv[0], b.head);
+}
+
+static int usage(const char *prog)
+{
+ fprintf(stderr,
+ "Usage: %s [<options>] <command> [arguments...]\n"
+ "Options:\n"
+ " -s <socket>: Set the unix domain socket to connect to\n"
+ "\n"
+ "Commands:\n"
+ " - list [<path>] List objects\n"
+ " - call <path> <method> [<message>] Call an object method\n"
+ " - listen [<path>...] Listen for events\n"
+ " - send <type> [<message>] Send an event\n"
+ "\n", prog);
+ return 1;
+}
+
+
+struct {
+ const char *name;
+ int (*cb)(struct ubus_context *ctx, int argc, char **argv);
+} commands[] = {
+ { "list", ubus_cli_list },
+ { "call", ubus_cli_call },
+ { "listen", ubus_cli_listen },
+ { "send", ubus_cli_send },
+};
+