Allow positional args for single-param commands

Less typing = more happy

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
wayvncctl-polishing
Jim Ramsay 2023-01-06 16:24:20 -05:00
parent e5ab6a3134
commit 23527a095a
3 changed files with 21 additions and 11 deletions

View File

@ -41,7 +41,7 @@ restore_outputs() {
local firstOutput=${OUTPUTS_TO_RECONNECT[0]} local firstOutput=${OUTPUTS_TO_RECONNECT[0]}
echo "Switching wayvnc back to physical output $firstOutput" echo "Switching wayvnc back to physical output $firstOutput"
wait_for_output_matching "$firstOutput" >/dev/null wait_for_output_matching "$firstOutput" >/dev/null
$WAYVNCCTL output-set --output-name="$firstOutput" $WAYVNCCTL output-set "$firstOutput"
echo "Removing virtual output $HEADLESS" echo "Removing virtual output $HEADLESS"
$SWAYMSG output "$HEADLESS" unplug $SWAYMSG output "$HEADLESS" unplug
fi fi
@ -55,14 +55,14 @@ collapse_outputs() {
local preexisting="$(find_output_matching 'HEADLESS-\\d+')" local preexisting="$(find_output_matching 'HEADLESS-\\d+')"
if [[ $preexisting ]]; then if [[ $preexisting ]]; then
echo "Switching to preexisting virtual output $preexisting" echo "Switching to preexisting virtual output $preexisting"
$WAYVNCCTL output-set --output-name="$preexisting" $WAYVNCCTL output-set "$preexisting"
else else
echo "Creating a virtual display" echo "Creating a virtual display"
$SWAYMSG create_output $SWAYMSG create_output
echo "Waiting for virtusl output to be created..." echo "Waiting for virtusl output to be created..."
HEADLESS=$(wait_for_output_matching 'HEADLESS-\\d+') HEADLESS=$(wait_for_output_matching 'HEADLESS-\\d+')
echo "Switching to virtual output $HEADLESS" echo "Switching to virtual output $HEADLESS"
$WAYVNCCTL output-set --output-name="$HEADLESS" $WAYVNCCTL output-set "$HEADLESS"
fi fi
fi fi
for output in $($WAYVNCCTL -j output-list | jq -r '.[] | select(.captured==false).name'); do for output in $($WAYVNCCTL -j output-list | jq -r '.[] | select(.captured==false).name'); do

View File

@ -733,7 +733,11 @@ static int print_command_usage(struct ctl_client* self,
WARN("No such command"); WARN("No such command");
return 1; 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); table_printer_indent_and_reflow_text(stdout, info->description, 80, 0, 0);
printf("\n"); printf("\n");
option_parser_print_options(cmd_options, stdout); option_parser_print_options(cmd_options, stdout);
@ -764,13 +768,19 @@ int ctl_client_init_cmd_parser(struct option_parser* parser, enum cmd_type cmd)
alloc_count++; alloc_count++;
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; size_t i = 0;
for (i = 0; i < param_count; ++i) { 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]; struct wv_option* option = &options[i];
option->long_opt = info->params[i].name; option->long_opt = info->params[i].name;
option->help = info->params[i].description; option->help = info->params[i].description;
option->schema = "<value>"; option->schema = "<value>";
} }
}
if (cmd == CMD_EVENT_RECEIVE) { if (cmd == CMD_EVENT_RECEIVE) {
options[i].long_opt = "show"; options[i].long_opt = "show";
options[i].schema = "<event-name>"; options[i].schema = "<event-name>";

View File

@ -109,7 +109,7 @@ Get help on the "output-set" IPC command:
``` ```
$ wayvncctl output-set --help $ wayvncctl output-set --help
Usage: wayvncctl [options] output-set [params] Usage: wayvncctl [options] output-set <output-name> [params]
... ...
``` ```