ovsdb-client: Add support for --detach to "monitor" command.
[cascardo/ovs.git] / ovsdb / ovsdb-client.c
1 /*
2  * Copyright (c) 2009 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <config.h>
18
19 #include <errno.h>
20 #include <getopt.h>
21 #include <limits.h>
22 #include <signal.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26
27 #include "command-line.h"
28 #include "column.h"
29 #include "compiler.h"
30 #include "daemon.h"
31 #include "dynamic-string.h"
32 #include "json.h"
33 #include "jsonrpc.h"
34 #include "ovsdb.h"
35 #include "ovsdb-error.h"
36 #include "stream.h"
37 #include "table.h"
38 #include "timeval.h"
39 #include "util.h"
40
41 #include "vlog.h"
42 #define THIS_MODULE VLM_ovsdb_client
43
44 /* --format: Output formatting. */
45 static enum {
46     FMT_TABLE,                  /* Textual table. */
47     FMT_HTML,                   /* HTML table. */
48     FMT_CSV                     /* Comma-separated lines. */
49 } output_format;
50
51 /* --wide: For --format=table, the maximum output width. */
52 static int output_width;
53
54 /* --no-headings: Whether table output should include headings. */
55 static int output_headings = true;
56
57 static const struct command all_commands[];
58
59 static void usage(void) NO_RETURN;
60 static void parse_options(int argc, char *argv[]);
61
62 int
63 main(int argc, char *argv[])
64 {
65     set_program_name(argv[0]);
66     time_init();
67     vlog_init();
68     parse_options(argc, argv);
69     signal(SIGPIPE, SIG_IGN);
70     run_command(argc - optind, argv + optind, all_commands);
71     return 0;
72 }
73
74 static void
75 parse_options(int argc, char *argv[])
76 {
77     static struct option long_options[] = {
78         {"wide", no_argument, &output_width, INT_MAX},
79         {"format", required_argument, 0, 'f'},
80             {"no-headings", no_argument, &output_headings, 0},
81         {"verbose", optional_argument, 0, 'v'},
82         {"help", no_argument, 0, 'h'},
83         {"version", no_argument, 0, 'V'},
84         DAEMON_LONG_OPTIONS,
85         {0, 0, 0, 0},
86     };
87     char *short_options = long_options_to_short_options(long_options);
88
89     output_width = isatty(fileno(stdout)) ? 79 : INT_MAX;
90     for (;;) {
91         int c;
92
93         c = getopt_long(argc, argv, short_options, long_options, NULL);
94         if (c == -1) {
95             break;
96         }
97
98         switch (c) {
99         case 'f':
100             if (!strcmp(optarg, "table")) {
101                 output_format = FMT_TABLE;
102             } else if (!strcmp(optarg, "html")) {
103                 output_format = FMT_HTML;
104             } else if (!strcmp(optarg, "csv")) {
105                 output_format = FMT_CSV;
106             } else {
107                 ovs_fatal(0, "unknown output format \"%s\"", optarg);
108             }
109             break;
110
111         case 'w':
112             output_width = INT_MAX;
113             break;
114
115         case 'h':
116             usage();
117
118         case 'V':
119             OVS_PRINT_VERSION(0, 0);
120             exit(EXIT_SUCCESS);
121
122         case 'v':
123             vlog_set_verbosity(optarg);
124             break;
125
126         DAEMON_OPTION_HANDLERS
127
128         case '?':
129             exit(EXIT_FAILURE);
130
131         case 0:
132             /* getopt_long() already set the value for us. */
133             break;
134
135         default:
136             abort();
137         }
138     }
139     free(short_options);
140 }
141
142 static void
143 usage(void)
144 {
145     printf("%s: Open vSwitch database JSON-RPC client\n"
146            "usage: %s [OPTIONS] COMMAND [ARG...]\n"
147            "\nValid commands are:\n"
148            "\n  get-schema SERVER\n"
149            "    retrieve schema from SERVER\n"
150            "\n  list-tables SERVER\n"
151            "    list SERVER's tables\n"
152            "\n  list-columns SERVER [TABLE]\n"
153            "    list columns in TABLE (or all tables) on SERVER\n"
154            "\n  transact SERVER TRANSACTION\n"
155            "    run TRANSACTION (a JSON array of operations) on SERVER\n"
156            "    and print the results as JSON on stdout\n"
157            "\n  monitor SERVER TABLE [COLUMN,...] [SELECT,...]\n"
158            "    monitor contents of (COLUMNs in) TABLE on SERVER\n"
159            "    Valid SELECTs are: initial, insert, delete, modify\n",
160            program_name, program_name);
161     stream_usage("SERVER", true, true);
162     printf("\nOutput formatting options:\n"
163            "  -f, --format=FORMAT         set output formatting to FORMAT\n"
164            "                              (\"table\", \"html\", or \"csv\"\n"
165            "  --wide                      don't limit TTY lines to 79 bytes\n"
166            "  --no-headings               omit table heading row\n");
167     daemon_usage();
168     vlog_usage();
169     printf("\nOther options:\n"
170            "  -h, --help                  display this help message\n"
171            "  -V, --version               display version information\n");
172     exit(EXIT_SUCCESS);
173 }
174 \f
175 static struct json *
176 parse_json(const char *s)
177 {
178     struct json *json = json_from_string(s);
179     if (json->type == JSON_STRING) {
180         ovs_fatal(0, "\"%s\": %s", s, json->u.string);
181     }
182     return json;
183 }
184
185 static struct jsonrpc *
186 open_jsonrpc(const char *server)
187 {
188     struct stream *stream;
189     int error;
190
191     error = stream_open_block(server, &stream);
192     if (error == EAFNOSUPPORT) {
193         struct pstream *pstream;
194
195         error = pstream_open(server, &pstream);
196         if (error) {
197             ovs_fatal(error, "failed to connect or listen to \"%s\"", server);
198         }
199
200         VLOG_INFO("%s: waiting for connection...", server);
201         error = pstream_accept_block(pstream, &stream);
202         if (error) {
203             ovs_fatal(error, "failed to accept connection on \"%s\"", server);
204         }
205
206         pstream_close(pstream);
207     } else if (error) {
208         ovs_fatal(error, "failed to connect to \"%s\"", server);
209     }
210
211     return jsonrpc_open(stream);
212 }
213
214 static void
215 print_json(struct json *json)
216 {
217     char *string = json_to_string(json, JSSF_SORT);
218     fputs(string, stdout);
219     free(string);
220 }
221
222 static void
223 print_and_free_json(struct json *json)
224 {
225     print_json(json);
226     json_destroy(json);
227 }
228
229 static void
230 check_ovsdb_error(struct ovsdb_error *error)
231 {
232     if (error) {
233         ovs_fatal(0, "%s", ovsdb_error_to_string(error));
234     }
235 }
236
237 static struct ovsdb_schema *
238 fetch_schema_from_rpc(struct jsonrpc *rpc)
239 {
240     struct jsonrpc_msg *request, *reply;
241     struct ovsdb_schema *schema;
242     int error;
243
244     request = jsonrpc_create_request("get_schema", json_array_create_empty(),
245                                      NULL);
246     error = jsonrpc_transact_block(rpc, request, &reply);
247     if (error) {
248         ovs_fatal(error, "transaction failed");
249     }
250     check_ovsdb_error(ovsdb_schema_from_json(reply->result, &schema));
251     jsonrpc_msg_destroy(reply);
252
253     return schema;
254 }
255
256 static struct ovsdb_schema *
257 fetch_schema(const char *server)
258 {
259     struct ovsdb_schema *schema;
260     struct jsonrpc *rpc;
261
262     rpc = open_jsonrpc(server);
263     schema = fetch_schema_from_rpc(rpc);
264     jsonrpc_close(rpc);
265
266     return schema;
267 }
268 \f
269 struct column {
270     char *heading;
271     int width;
272 };
273
274 struct table {
275     char **cells;
276     struct column *columns;
277     size_t n_columns, allocated_columns;
278     size_t n_rows, allocated_rows;
279     size_t current_column;
280 };
281
282 static void
283 table_init(struct table *table)
284 {
285     memset(table, 0, sizeof *table);
286 }
287
288 static void
289 table_destroy(struct table *table)
290 {
291     size_t i;
292
293     for (i = 0; i < table->n_columns; i++) {
294         free(table->columns[i].heading);
295     }
296     free(table->columns);
297
298     for (i = 0; i < table->n_columns * table->n_rows; i++) {
299         free(table->cells[i]);
300     }
301     free(table->cells);
302 }
303
304 static void
305 table_add_column(struct table *table, const char *heading, ...)
306     PRINTF_FORMAT(2, 3);
307
308 static void
309 table_add_column(struct table *table, const char *heading, ...)
310 {
311     struct column *column;
312     va_list args;
313
314     assert(!table->n_rows);
315     if (table->n_columns >= table->allocated_columns) {
316         table->columns = x2nrealloc(table->columns, &table->allocated_columns,
317                                     sizeof *table->columns);
318     }
319     column = &table->columns[table->n_columns++];
320
321     va_start(args, heading);
322     column->heading = xvasprintf(heading, args);
323     column->width = strlen(column->heading);
324     va_end(args);
325 }
326
327 static char **
328 table_cell__(const struct table *table, size_t row, size_t column)
329 {
330     return &table->cells[column + row * table->n_columns];
331 }
332
333 static void
334 table_add_row(struct table *table)
335 {
336     size_t x, y;
337
338     if (table->n_rows >= table->allocated_rows) {
339         table->cells = x2nrealloc(table->cells, &table->allocated_rows,
340                                   table->n_columns * sizeof *table->cells);
341     }
342
343     y = table->n_rows++;
344     table->current_column = 0;
345     for (x = 0; x < table->n_columns; x++) {
346         *table_cell__(table, y, x) = NULL;
347     }
348 }
349
350 static void
351 table_add_cell_nocopy(struct table *table, char *s)
352 {
353     size_t x, y;
354     int length;
355
356     assert(table->n_rows > 0);
357     assert(table->current_column < table->n_columns);
358
359     x = table->current_column++;
360     y = table->n_rows - 1;
361     *table_cell__(table, y, x) = s;
362
363     length = strlen(s);
364     if (length > table->columns[x].width) {
365         table->columns[x].width = length;
366     }
367 }
368
369 static void
370 table_add_cell(struct table *table, const char *format, ...)
371 {
372     va_list args;
373
374     va_start(args, format);
375     table_add_cell_nocopy(table, xvasprintf(format, args));
376     va_end(args);
377 }
378
379 static void
380 table_print_table_line__(struct ds *line, size_t max_width)
381 {
382     ds_truncate(line, max_width);
383     puts(ds_cstr(line));
384     ds_clear(line);
385 }
386
387 static void
388 table_print_table__(const struct table *table)
389 {
390     struct ds line = DS_EMPTY_INITIALIZER;
391     size_t x, y;
392
393     if (output_headings) {
394         for (x = 0; x < table->n_columns; x++) {
395             const struct column *column = &table->columns[x];
396             if (x) {
397                 ds_put_char(&line, ' ');
398             }
399             ds_put_format(&line, "%-*s", column->width, column->heading);
400         }
401         table_print_table_line__(&line, output_width);
402
403         for (x = 0; x < table->n_columns; x++) {
404             const struct column *column = &table->columns[x];
405             int i;
406
407             if (x) {
408                 ds_put_char(&line, ' ');
409             }
410             for (i = 0; i < column->width; i++) {
411                 ds_put_char(&line, '-');
412             }
413         }
414         table_print_table_line__(&line, output_width);
415     }
416
417     for (y = 0; y < table->n_rows; y++) {
418         for (x = 0; x < table->n_columns; x++) {
419             const char *cell = *table_cell__(table, y, x);
420             if (x) {
421                 ds_put_char(&line, ' ');
422             }
423             ds_put_format(&line, "%-*s", table->columns[x].width, cell);
424         }
425         table_print_table_line__(&line, output_width);
426     }
427
428     ds_destroy(&line);
429 }
430
431 static void
432 table_print_html_cell__(const char *element, const char *content)
433 {
434     const char *p;
435
436     printf("    <%s>", element);
437     for (p = content; *p != '\0'; p++) {
438         switch (*p) {
439         case '&':
440             fputs("&amp;", stdout);
441             break;
442         case '<':
443             fputs("&lt;", stdout);
444             break;
445         case '>':
446             fputs("&gt;", stdout);
447             break;
448         default:
449             putchar(*p);
450             break;
451         }
452     }
453     printf("</%s>\n", element);
454 }
455
456 static void
457 table_print_html__(const struct table *table)
458 {
459     size_t x, y;
460
461     fputs("<table>\n", stdout);
462
463     if (output_headings) {
464         fputs("  <tr>\n", stdout);
465         for (x = 0; x < table->n_columns; x++) {
466             const struct column *column = &table->columns[x];
467             table_print_html_cell__("th", column->heading);
468         }
469         fputs("  </tr>\n", stdout);
470     }
471
472     for (y = 0; y < table->n_rows; y++) {
473         fputs("  <tr>\n", stdout);
474         for (x = 0; x < table->n_columns; x++) {
475             table_print_html_cell__("td", *table_cell__(table, y, x));
476         }
477         fputs("  </tr>\n", stdout);
478     }
479
480     fputs("</table>\n", stdout);
481 }
482
483 static void
484 table_print_csv_cell__(const char *content)
485 {
486     const char *p;
487
488     if (!strpbrk(content, "\n\",")) {
489         fputs(content, stdout);
490     } else {
491         putchar('"');
492         for (p = content; *p != '\0'; p++) {
493             switch (*p) {
494             case '"':
495                 fputs("\"\"", stdout);
496                 break;
497             default:
498                 putchar(*p);
499                 break;
500             }
501         }
502         putchar('"');
503     }
504 }
505
506 static void
507 table_print_csv__(const struct table *table)
508 {
509     size_t x, y;
510
511     if (output_headings) {
512         for (x = 0; x < table->n_columns; x++) {
513             const struct column *column = &table->columns[x];
514             if (x) {
515                 putchar(',');
516             }
517             table_print_csv_cell__(column->heading);
518         }
519         putchar('\n');
520     }
521
522     for (y = 0; y < table->n_rows; y++) {
523         for (x = 0; x < table->n_columns; x++) {
524             if (x) {
525                 putchar(',');
526             }
527             table_print_csv_cell__(*table_cell__(table, y, x));
528         }
529         putchar('\n');
530     }
531 }
532
533 static void
534 table_print(const struct table *table)
535 {
536     switch (output_format) {
537     case FMT_TABLE:
538         table_print_table__(table);
539         break;
540
541     case FMT_HTML:
542         table_print_html__(table);
543         break;
544
545     case FMT_CSV:
546         table_print_csv__(table);
547         break;
548     }
549 }
550 \f
551 static void
552 do_get_schema(int argc UNUSED, char *argv[])
553 {
554     struct ovsdb_schema *schema = fetch_schema(argv[1]);
555     print_and_free_json(ovsdb_schema_to_json(schema));
556     ovsdb_schema_destroy(schema);
557 }
558
559 static void
560 do_list_tables(int argc UNUSED, char *argv[])
561 {
562     struct ovsdb_schema *schema;
563     struct shash_node *node;
564     struct table t;
565
566     schema = fetch_schema(argv[1]);
567     table_init(&t);
568     table_add_column(&t, "Table");
569     table_add_column(&t, "Comment");
570     SHASH_FOR_EACH (node, &schema->tables) {
571         struct ovsdb_table_schema *ts = node->data;
572
573         table_add_row(&t);
574         table_add_cell(&t, ts->name);
575         if (ts->comment) {
576             table_add_cell(&t, ts->comment);
577         }
578     }
579     ovsdb_schema_destroy(schema);
580     table_print(&t);
581 }
582
583 static void
584 do_list_columns(int argc UNUSED, char *argv[])
585 {
586     const char *table_name = argv[2];
587     struct ovsdb_schema *schema;
588     struct shash_node *table_node;
589     struct table t;
590
591     schema = fetch_schema(argv[1]);
592     table_init(&t);
593     if (!table_name) {
594         table_add_column(&t, "Table");
595     }
596     table_add_column(&t, "Column");
597     table_add_column(&t, "Type");
598     table_add_column(&t, "Comment");
599     SHASH_FOR_EACH (table_node, &schema->tables) {
600         struct ovsdb_table_schema *ts = table_node->data;
601
602         if (!table_name || !strcmp(table_name, ts->name)) {
603             struct shash_node *column_node;
604
605             SHASH_FOR_EACH (column_node, &ts->columns) {
606                 struct ovsdb_column *column = column_node->data;
607                 struct json *type = ovsdb_type_to_json(&column->type);
608
609                 table_add_row(&t);
610                 if (!table_name) {
611                     table_add_cell(&t, ts->name);
612                 }
613                 table_add_cell(&t, column->name);
614                 table_add_cell_nocopy(&t, json_to_string(type, JSSF_SORT));
615                 if (column->comment) {
616                     table_add_cell(&t, column->comment);
617                 }
618
619                 json_destroy(type);
620             }
621         }
622     }
623     ovsdb_schema_destroy(schema);
624     table_print(&t);
625 }
626
627 static void
628 do_transact(int argc UNUSED, char *argv[])
629 {
630     struct jsonrpc_msg *request, *reply;
631     struct json *transaction;
632     struct jsonrpc *rpc;
633     int error;
634
635     transaction = parse_json(argv[2]);
636
637     rpc = open_jsonrpc(argv[1]);
638     request = jsonrpc_create_request("transact", transaction, NULL);
639     error = jsonrpc_transact_block(rpc, request, &reply);
640     if (error) {
641         ovs_fatal(error, "transaction failed");
642     }
643     if (reply->error) {
644         ovs_fatal(error, "transaction returned error: %s",
645                   json_to_string(reply->error, JSSF_SORT));
646     }
647     print_json(reply->result);
648     putchar('\n');
649     jsonrpc_msg_destroy(reply);
650     jsonrpc_close(rpc);
651 }
652
653 static void
654 monitor_print_row(struct json *row, const char *type, const char *uuid,
655                   const struct ovsdb_column_set *columns, struct table *t)
656 {
657     size_t i;
658
659     if (!row) {
660         ovs_error(0, "missing %s row", type);
661         return;
662     } else if (row->type != JSON_OBJECT) {
663         ovs_error(0, "<row> is not object");
664         return;
665     }
666
667     table_add_row(t);
668     table_add_cell(t, uuid);
669     table_add_cell(t, type);
670     for (i = 0; i < columns->n_columns; i++) {
671         const struct ovsdb_column *column = columns->columns[i];
672         struct json *value = shash_find_data(json_object(row), column->name);
673         if (value) {
674             table_add_cell_nocopy(t, json_to_string(value, JSSF_SORT));
675         } else {
676             table_add_cell(t, "");
677         }
678     }
679 }
680
681 static void
682 monitor_print(struct json *table_updates,
683               const struct ovsdb_table_schema *table,
684               const struct ovsdb_column_set *columns, bool initial)
685 {
686     struct json *table_update;
687     struct shash_node *node;
688     struct table t;
689     size_t i;
690
691     table_init(&t);
692
693     if (table_updates->type != JSON_OBJECT) {
694         ovs_error(0, "<table-updates> is not object");
695         return;
696     }
697     table_update = shash_find_data(json_object(table_updates), table->name);
698     if (!table_update) {
699         return;
700     }
701     if (table_update->type != JSON_OBJECT) {
702         ovs_error(0, "<table-update> is not object");
703         return;
704     }
705
706     table_add_column(&t, "row");
707     table_add_column(&t, "action");
708     for (i = 0; i < columns->n_columns; i++) {
709         table_add_column(&t, "%s", columns->columns[i]->name);
710     }
711     SHASH_FOR_EACH (node, json_object(table_update)) {
712         struct json *row_update = node->data;
713         struct json *old, *new;
714
715         if (row_update->type != JSON_OBJECT) {
716             ovs_error(0, "<row-update> is not object");
717             continue;
718         }
719         old = shash_find_data(json_object(row_update), "old");
720         new = shash_find_data(json_object(row_update), "new");
721         if (initial) {
722             monitor_print_row(new, "initial", node->name, columns, &t);
723         } else if (!old) {
724             monitor_print_row(new, "insert", node->name, columns, &t);
725         } else if (!new) {
726             monitor_print_row(old, "delete", node->name, columns, &t);
727         } else {
728             monitor_print_row(old, "old", node->name, columns, &t);
729             monitor_print_row(new, "new", "", columns, &t);
730         }
731     }
732     table_print(&t);
733     table_destroy(&t);
734 }
735
736 static void
737 do_monitor(int argc, char *argv[])
738 {
739     struct ovsdb_column_set columns = OVSDB_COLUMN_SET_INITIALIZER;
740     struct ovsdb_table_schema *table;
741     struct ovsdb_schema *schema;
742     struct jsonrpc_msg *request;
743     struct jsonrpc *rpc;
744     struct json *select, *monitor, *monitor_request, *monitor_requests,
745         *request_id;
746
747     rpc = open_jsonrpc(argv[1]);
748
749     schema = fetch_schema_from_rpc(rpc);
750     table = shash_find_data(&schema->tables, argv[2]);
751     if (!table) {
752         ovs_fatal(0, "%s: no table named \"%s\"", argv[1], argv[2]);
753     }
754
755     if (argc >= 4 && *argv[3] != '\0') {
756         char *save_ptr = NULL;
757         char *token;
758
759         for (token = strtok_r(argv[3], ",", &save_ptr); token != NULL;
760              token = strtok_r(NULL, ",", &save_ptr)) {
761             const struct ovsdb_column *column;
762             column = ovsdb_table_schema_get_column(table, token);
763             if (!column) {
764                 ovs_fatal(0, "%s: table \"%s\" does not have a "
765                           "column named \"%s\"", argv[1], argv[2], token);
766             }
767             ovsdb_column_set_add(&columns, column);
768         }
769     } else {
770         struct shash_node *node;
771
772         SHASH_FOR_EACH (node, &table->columns) {
773             const struct ovsdb_column *column = node->data;
774             if (column->index != OVSDB_COL_UUID) {
775                 ovsdb_column_set_add(&columns, column);
776             }
777         }
778     }
779
780     if (argc >= 5 && *argv[4] != '\0') {
781         char *save_ptr = NULL;
782         char *token;
783
784         select = json_object_create();
785         for (token = strtok_r(argv[4], ",", &save_ptr); token != NULL;
786              token = strtok_r(NULL, ",", &save_ptr)) {
787             json_object_put(select, token, json_boolean_create(true));
788         }
789     } else {
790         select = NULL;
791     }
792
793     monitor_request = json_object_create();
794     json_object_put(monitor_request,
795                     "columns", ovsdb_column_set_to_json(&columns));
796     if (select) {
797         json_object_put(monitor_request, "select", select);
798     }
799
800     monitor_requests = json_object_create();
801     json_object_put(monitor_requests, argv[2], monitor_request);
802
803     monitor = json_array_create_2(json_null_create(), monitor_requests);
804     request = jsonrpc_create_request("monitor", monitor, NULL);
805     request_id = json_clone(request->id);
806     jsonrpc_send(rpc, request);
807     for (;;) {
808         struct jsonrpc_msg *msg;
809         int error;
810
811         error = jsonrpc_recv_block(rpc, &msg);
812         if (error) {
813             ovs_fatal(error, "%s: receive failed", argv[1]);
814         }
815
816         if (msg->type == JSONRPC_REQUEST && !strcmp(msg->method, "echo")) {
817             jsonrpc_send(rpc, jsonrpc_create_reply(json_clone(msg->params),
818                                                    msg->id));
819         } else if (msg->type == JSONRPC_REPLY
820                    && json_equal(msg->id, request_id)) {
821             monitor_print(msg->result, table, &columns, true);
822             fflush(stdout);
823             daemonize();
824         } else if (msg->type == JSONRPC_NOTIFY
825                    && !strcmp(msg->method, "update")) {
826             struct json *params = msg->params;
827             if (params->type == JSON_ARRAY
828                 && params->u.array.n == 2
829                 && params->u.array.elems[0]->type == JSON_NULL) {
830                 monitor_print(params->u.array.elems[1],
831                               table, &columns, false);
832                 fflush(stdout);
833             }
834         }
835     }
836 }
837
838 static void
839 do_help(int argc UNUSED, char *argv[] UNUSED)
840 {
841     usage();
842 }
843
844 static const struct command all_commands[] = {
845     { "get-schema", 1, 1, do_get_schema },
846     { "list-tables", 1, 1, do_list_tables },
847     { "list-columns", 1, 2, do_list_columns },
848     { "transact", 2, 2, do_transact },
849     { "monitor", 2, 4, do_monitor },
850     { "help", 0, INT_MAX, do_help },
851     { NULL, 0, 0, NULL },
852 };