From dcb23ebfe1b52e0b32ade16dcbebe5d58cbe4196 Mon Sep 17 00:00:00 2001 From: Jim Ramsay Date: Wed, 11 Jan 2023 05:19:46 -0500 Subject: [PATCH] Add 'schema' to wayvncctl command parameters Signed-off-by: Jim Ramsay --- include/ctl-commands.h | 4 +++ src/ctl-client.c | 30 ++++++++++++---------- src/ctl-commands.c | 58 +++++++++++++++++++++++++++--------------- 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/include/ctl-commands.h b/include/ctl-commands.h index 1fd2606..9ba987c 100644 --- a/include/ctl-commands.h +++ b/include/ctl-commands.h @@ -16,6 +16,8 @@ #pragma once +#include + enum cmd_type { CMD_HELP, CMD_EVENT_RECEIVE, @@ -41,6 +43,8 @@ enum event_type { struct cmd_param_info { char* name; char* description; + char* schema; + bool positional; }; struct cmd_info { diff --git a/src/ctl-client.c b/src/ctl-client.c index b01228e..07cf2ad 100644 --- a/src/ctl-client.c +++ b/src/ctl-client.c @@ -663,6 +663,11 @@ void ctl_client_print_command_list(FILE* stream) fprintf(stream, "\nRun 'wayvncctl command-name --help' for command-specific details.\n"); } +static size_t param_render_length(const struct cmd_param_info* param) +{ + return strlen(param->name) + strlen(param->schema) + 1; +} + static void print_event_info(const struct cmd_info* info) { printf("%s\n\n", info->name); @@ -671,14 +676,14 @@ static void print_event_info(const struct cmd_info* info) printf("\nData fields:\n"); size_t max_namelen = 0; for (int i = 0; info->params[i].name != NULL; ++i) - max_namelen = MAX(max_namelen, strlen(info->params[i].name)); + max_namelen = MAX(max_namelen, param_render_length(&info->params[i])); struct table_printer printer; table_printer_init(&printer, stdout, max_namelen); for (int i = 0; info->params[i].name != NULL; ++i) table_printer_print_fmtline(&printer, info->params[i].description, - "%s=...", info->params[i].name); + "%s=%s", info->params[i].name, info->params[i].schema); } } @@ -772,17 +777,16 @@ int ctl_client_init_cmd_parser(struct option_parser* parser, enum cmd_type cmd) struct wv_option* options = calloc(alloc_count, sizeof(struct wv_option)); size_t i = 0; - if (param_count == 1) { - // Represent a single parameter as a positional argument - options[0].positional = info->params[0].name; - options[0].help = info->params[0].description; - i++; - } else { - for (; i < param_count; ++i) { - struct wv_option* option = &options[i]; - option->long_opt = info->params[i].name; - option->help = info->params[i].description; - option->schema = ""; + for (; i < param_count; ++i) { + struct wv_option* option = &options[i]; + struct cmd_param_info* param = &info->params[i]; + option->help = param->description; + if (param->positional) { + option->positional = param->name; + option->help = param->description; + } else { + option->long_opt = param->name; + option->schema = param->schema; } } if (cmd == CMD_EVENT_RECEIVE) { diff --git a/src/ctl-commands.c b/src/ctl-commands.c index 03f101c..0f59fe9 100644 --- a/src/ctl-commands.c +++ b/src/ctl-commands.c @@ -23,65 +23,83 @@ struct cmd_info ctl_command_list[] = { [CMD_HELP] = { "help", "List all commands and events, or show usage of a specific command or event", { - {"command", "The command to show (optional)"}, - {"event", "The event to show (optional)"}, - { }, + { "command", + "The command to show (optional)", + "" }, + { "event", + "The event to show (optional)", + "" }, + {}, } }, [CMD_VERSION] = { "version", "Query the version of the wayvnc process", - {{NULL, NULL}} + {{}} }, [CMD_EVENT_RECEIVE] = { "event-receive", "Register to begin receiving asynchronous events from wayvnc", // TODO: Event type filtering? - {{ }} + {{}} }, [CMD_CLIENT_LIST] = { "client-list", "Return a list of all currently connected VNC sessions", - {{NULL, NULL}} + {{}} }, [CMD_CLIENT_DISCONNECT] = { "client-disconnect", "Disconnect a VNC session", { - {"id", "The ID of the client to disconnect"}, - { }, + { "id", + "The ID of the client to disconnect", + "", true }, + {}, } }, [CMD_OUTPUT_LIST] = { "output-list", "Return a list of all currently detected Wayland outputs", - {{NULL, NULL}} + {{}} }, [CMD_OUTPUT_CYCLE] = { "output-cycle", "Cycle the actively captured output to the next available output, wrapping through all outputs.", - {{ }} + {{}} }, [CMD_OUTPUT_SET] = { "output-set", "Switch the actively captured output", { - {"output-name", "The specific output name to capture"}, - { }, + { "output-name", + "The specific output name to capture", + "", true }, + {}, } }, [CMD_WAYVNC_EXIT] = { "wayvnc-exit", "Disconnect all clients and shut down wayvnc", - {{ }}, + {{}}, }, }; #define CLIENT_EVENT_PARAMS(including) \ - {"id", "A unique identifier for this client"}, \ - {"connection_count", "The total number of connected VNC clients " including " this one."}, \ - {"hostname", "The hostname or IP address of this client (may be null)"}, \ - {"username", "The username used to authentice this client (may be null)."}, \ - {NULL, NULL}, + { "id", \ + "A unique identifier for this client", \ + "" }, \ + { "connection_count", \ + "The total number of connected VNC clients " including " this one.", \ + "" }, \ + { "hostname", \ + "The hostname or IP address of this client (may be null)", \ + "" }, \ + { "username", \ + "The username used to authentice this client (may be null).", \ + "" }, \ + {}, struct cmd_info ctl_event_list[] = { [EVT_CAPTURE_CHANGED] = {"capture-changed", "Sent by wayvnc when the catured output is changed", { - {"output", "The name of the output now being captured"}, - {NULL, NULL}, + { "output-name", + "The name of the output now being captured", + "" }, + {}, }, }, [EVT_CLIENT_CONNECTED] = {"client-connected",