Change approach with getting commands out of help.

There are currently two ways for specify available commands in
vboxmanage help:

Usage:

  VBoxManage [<general option>] <command>
[..]
Commands:

  command1 ...

  command2 ...

and:

  VBoxManage command3 ...

  VBoxManage command4 ...

besides the fact how it is annoying for parsing the output (or lack of
having some way for machine readable format for commands), I have
treated the latter as a exception from general rule, but lately it
slowly moving towards the second form. In this patch it is adapted to
also parse second format instead of adding those commands manually.

Also, there was missing parameter added for sharedfolder add command.
This commit is contained in:
2021-07-27 20:00:50 +02:00
parent 8360d95123
commit 82e2fade6b

View File

@@ -486,16 +486,18 @@ _VBoxManage() {
# all possible commands for the VBoxManage
opts=$(VBoxManage -q help | \
egrep -o "^\s\s[a-z]+ " | \
grep -E -o "^\s\s[a-z]+ " | \
grep -v VBoxManage | \
awk '{print $1}'| \
sort | \
uniq)
# Add some commands manually, since they are listed differently in
# vboxmanage help.
opts="${opts} mediumio debugvm unattended extpack clonevm snapshot
dhcpserver cloudprofile cloud"
# Add commands which are defined as ` VBoxManage commandname ` in a help.
opts="${opts} $(VBoxManage -q help | \
grep -E -o '^\s\s[a-zA-Z]+\s[a-z]+' | \
awk '{print $2}'| \
sort | \
uniq)"
if [[ ${cur} == "-q" || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
@@ -2304,7 +2306,7 @@ _VBoxManage() {
case "${subcommand}" in
add)
items=(--name --hostpath --transient --readonly
--automount)
--automount --auto-mount-point)
_get_excluded_items "${items[@]}"
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
;;