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
#include <stdbool.h>
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 {

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");
}
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 = "<value>";
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) {

View File

@ -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)",
"<name>" },
{ "event",
"The event to show (optional)",
"<name>" },
{},
}
},
[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",
"<id>", 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",
"<name>", 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", \
"<id>" }, \
{ "connection_count", \
"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[] = {
[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",
"<name>" },
{},
},
},
[EVT_CLIENT_CONNECTED] = {"client-connected",