Add 'schema' to wayvncctl command parameters

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
wayvncctl-polishing
Jim Ramsay 2023-01-11 05:19:46 -05:00
parent a52b7a1985
commit dcb23ebfe1
3 changed files with 59 additions and 33 deletions

View File

@ -16,6 +16,8 @@
#pragma once #pragma once
#include <stdbool.h>
enum cmd_type { enum cmd_type {
CMD_HELP, CMD_HELP,
CMD_EVENT_RECEIVE, CMD_EVENT_RECEIVE,
@ -41,6 +43,8 @@ enum event_type {
struct cmd_param_info { struct cmd_param_info {
char* name; char* name;
char* description; char* description;
char* schema;
bool positional;
}; };
struct cmd_info { struct cmd_info {

View File

@ -663,6 +663,11 @@ void ctl_client_print_command_list(FILE* stream)
fprintf(stream, "\nRun 'wayvncctl command-name --help' for command-specific details.\n"); 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) static void print_event_info(const struct cmd_info* info)
{ {
printf("%s\n\n", info->name); printf("%s\n\n", info->name);
@ -671,14 +676,14 @@ static void print_event_info(const struct cmd_info* info)
printf("\nData fields:\n"); printf("\nData fields:\n");
size_t max_namelen = 0; size_t max_namelen = 0;
for (int i = 0; info->params[i].name != NULL; ++i) 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; struct table_printer printer;
table_printer_init(&printer, stdout, max_namelen); table_printer_init(&printer, stdout, max_namelen);
for (int i = 0; info->params[i].name != NULL; ++i) for (int i = 0; info->params[i].name != NULL; ++i)
table_printer_print_fmtline(&printer, table_printer_print_fmtline(&printer,
info->params[i].description, 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, struct wv_option* options = calloc(alloc_count,
sizeof(struct wv_option)); sizeof(struct wv_option));
size_t i = 0; size_t i = 0;
if (param_count == 1) { for (; i < param_count; ++i) {
// Represent a single parameter as a positional argument struct wv_option* option = &options[i];
options[0].positional = info->params[0].name; struct cmd_param_info* param = &info->params[i];
options[0].help = info->params[0].description; option->help = param->description;
i++; if (param->positional) {
} else { option->positional = param->name;
for (; i < param_count; ++i) { option->help = param->description;
struct wv_option* option = &options[i]; } else {
option->long_opt = info->params[i].name; option->long_opt = param->name;
option->help = info->params[i].description; option->schema = param->schema;
option->schema = "<value>";
} }
} }
if (cmd == CMD_EVENT_RECEIVE) { if (cmd == CMD_EVENT_RECEIVE) {

View File

@ -23,65 +23,83 @@ struct cmd_info ctl_command_list[] = {
[CMD_HELP] = { "help", [CMD_HELP] = { "help",
"List all commands and events, or show usage of a specific command or event", "List all commands and events, or show usage of a specific command or event",
{ {
{"command", "The command to show (optional)"}, { "command",
{"event", "The event to show (optional)"}, "The command to show (optional)",
{ }, "<name>" },
{ "event",
"The event to show (optional)",
"<name>" },
{},
} }
}, },
[CMD_VERSION] = { "version", [CMD_VERSION] = { "version",
"Query the version of the wayvnc process", "Query the version of the wayvnc process",
{{NULL, NULL}} {{}}
}, },
[CMD_EVENT_RECEIVE] = { "event-receive", [CMD_EVENT_RECEIVE] = { "event-receive",
"Register to begin receiving asynchronous events from wayvnc", "Register to begin receiving asynchronous events from wayvnc",
// TODO: Event type filtering? // TODO: Event type filtering?
{{ }} {{}}
}, },
[CMD_CLIENT_LIST] = { "client-list", [CMD_CLIENT_LIST] = { "client-list",
"Return a list of all currently connected VNC sessions", "Return a list of all currently connected VNC sessions",
{{NULL, NULL}} {{}}
}, },
[CMD_CLIENT_DISCONNECT] = { "client-disconnect", [CMD_CLIENT_DISCONNECT] = { "client-disconnect",
"Disconnect a VNC session", "Disconnect a VNC session",
{ {
{"id", "The ID of the client to disconnect"}, { "id",
{ }, "The ID of the client to disconnect",
"<id>", true },
{},
} }
}, },
[CMD_OUTPUT_LIST] = { "output-list", [CMD_OUTPUT_LIST] = { "output-list",
"Return a list of all currently detected Wayland outputs", "Return a list of all currently detected Wayland outputs",
{{NULL, NULL}} {{}}
}, },
[CMD_OUTPUT_CYCLE] = { "output-cycle", [CMD_OUTPUT_CYCLE] = { "output-cycle",
"Cycle the actively captured output to the next available output, wrapping through all outputs.", "Cycle the actively captured output to the next available output, wrapping through all outputs.",
{{ }} {{}}
}, },
[CMD_OUTPUT_SET] = { "output-set", [CMD_OUTPUT_SET] = { "output-set",
"Switch the actively captured output", "Switch the actively captured output",
{ {
{"output-name", "The specific output name to capture"}, { "output-name",
{ }, "The specific output name to capture",
"<name>", true },
{},
} }
}, },
[CMD_WAYVNC_EXIT] = { "wayvnc-exit", [CMD_WAYVNC_EXIT] = { "wayvnc-exit",
"Disconnect all clients and shut down wayvnc", "Disconnect all clients and shut down wayvnc",
{{ }}, {{}},
}, },
}; };
#define CLIENT_EVENT_PARAMS(including) \ #define CLIENT_EVENT_PARAMS(including) \
{"id", "A unique identifier for this client"}, \ { "id", \
{"connection_count", "The total number of connected VNC clients " including " this one."}, \ "A unique identifier for this client", \
{"hostname", "The hostname or IP address of this client (may be null)"}, \ "<id>" }, \
{"username", "The username used to authentice this client (may be null)."}, \ { "connection_count", \
{NULL, NULL}, "The total number of connected VNC clients " including " this one.", \
"<count>" }, \
{ "hostname", \
"The hostname or IP address of this client (may be null)", \
"<name|ip>" }, \
{ "username", \
"The username used to authentice this client (may be null).", \
"<name>" }, \
{},
struct cmd_info ctl_event_list[] = { struct cmd_info ctl_event_list[] = {
[EVT_CAPTURE_CHANGED] = {"capture-changed", [EVT_CAPTURE_CHANGED] = {"capture-changed",
"Sent by wayvnc when the catured output is changed", "Sent by wayvnc when the catured output is changed",
{ {
{"output", "The name of the output now being captured"}, { "output-name",
{NULL, NULL}, "The name of the output now being captured",
"<name>" },
{},
}, },
}, },
[EVT_CLIENT_CONNECTED] = {"client-connected", [EVT_CLIENT_CONNECTED] = {"client-connected",