Allow positional args for single-param commands
Less typing = more happy Signed-off-by: Jim Ramsay <i.am@jimramsay.com>wayvncctl-polishing
parent
e5ab6a3134
commit
23527a095a
|
@ -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
|
||||||
|
|
|
@ -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,12 +768,18 @@ 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) {
|
||||||
struct wv_option* option = &options[i];
|
// Represent a single parameter as a positional argument
|
||||||
option->long_opt = info->params[i].name;
|
options[0].positional = info->params[0].name;
|
||||||
option->help = info->params[i].description;
|
i++;
|
||||||
option->schema = "<value>";
|
} 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>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (cmd == CMD_EVENT_RECEIVE) {
|
if (cmd == CMD_EVENT_RECEIVE) {
|
||||||
options[i].long_opt = "show";
|
options[i].long_opt = "show";
|
||||||
|
|
|
@ -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]
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue