From 23527a095a3cce86a111df7d1122f9c834812e2d Mon Sep 17 00:00:00 2001 From: Jim Ramsay Date: Fri, 6 Jan 2023 16:24:20 -0500 Subject: [PATCH] Allow positional args for single-param commands Less typing = more happy Signed-off-by: Jim Ramsay --- examples/single-output-sway | 6 +++--- src/ctl-client.c | 24 +++++++++++++++++------- wayvncctl.scd | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/examples/single-output-sway b/examples/single-output-sway index b9ef72c..fb99131 100755 --- a/examples/single-output-sway +++ b/examples/single-output-sway @@ -41,7 +41,7 @@ restore_outputs() { local firstOutput=${OUTPUTS_TO_RECONNECT[0]} echo "Switching wayvnc back to physical output $firstOutput" wait_for_output_matching "$firstOutput" >/dev/null - $WAYVNCCTL output-set --output-name="$firstOutput" + $WAYVNCCTL output-set "$firstOutput" echo "Removing virtual output $HEADLESS" $SWAYMSG output "$HEADLESS" unplug fi @@ -55,14 +55,14 @@ collapse_outputs() { local preexisting="$(find_output_matching 'HEADLESS-\\d+')" if [[ $preexisting ]]; then echo "Switching to preexisting virtual output $preexisting" - $WAYVNCCTL output-set --output-name="$preexisting" + $WAYVNCCTL output-set "$preexisting" else echo "Creating a virtual display" $SWAYMSG create_output echo "Waiting for virtusl output to be created..." HEADLESS=$(wait_for_output_matching 'HEADLESS-\\d+') echo "Switching to virtual output $HEADLESS" - $WAYVNCCTL output-set --output-name="$HEADLESS" + $WAYVNCCTL output-set "$HEADLESS" fi fi for output in $($WAYVNCCTL -j output-list | jq -r '.[] | select(.captured==false).name'); do diff --git a/src/ctl-client.c b/src/ctl-client.c index 262e109..b17064e 100644 --- a/src/ctl-client.c +++ b/src/ctl-client.c @@ -733,7 +733,11 @@ static int print_command_usage(struct ctl_client* self, WARN("No such command"); return 1; } - printf("Usage: wayvncctl [options] %s [parameters]\n\n", info->name); + printf("Usage: wayvncctl [options] %s ", info->name); + for (int i = 0; i < cmd_options->n_opts; ++i) + if (cmd_options->options[i].positional) + printf("<%s> ", cmd_options->options[i].positional); + printf("[parameters]\n\n"); table_printer_indent_and_reflow_text(stdout, info->description, 80, 0, 0); printf("\n"); option_parser_print_options(cmd_options, stdout); @@ -764,12 +768,18 @@ int ctl_client_init_cmd_parser(struct option_parser* parser, enum cmd_type cmd) alloc_count++; struct wv_option* options = calloc(alloc_count, sizeof(struct wv_option)); - size_t i; - for (i = 0; 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 = ""; + size_t i = 0; + if (param_count == 1) { + // Represent a single parameter as a positional argument + options[0].positional = info->params[0].name; + 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 = ""; + } } if (cmd == CMD_EVENT_RECEIVE) { options[i].long_opt = "show"; diff --git a/wayvncctl.scd b/wayvncctl.scd index 5c906a7..abc8040 100644 --- a/wayvncctl.scd +++ b/wayvncctl.scd @@ -109,7 +109,7 @@ Get help on the "output-set" IPC command: ``` $ wayvncctl output-set --help -Usage: wayvncctl [options] output-set [params] +Usage: wayvncctl [options] output-set [params] ... ```