In some cases (e.g. when virt-admin connects to the default URI)
some info message is printed onto stdout (using vshPrintExtra()).
This hurts user experience, just consider:
virt-admin<TAB><TAB>
NOTE\:\ Connecting\ to\ default\ daemon.\ Specify\ daemon\ using\ -c\ \(e.g.\ virtqemud\:///system\)
when no daemon is running. Suppress extra prints by passing '-q'
in the bash-completion script.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Instead of creating an empty object and then setting keys one
at a time, it is possible to pass a dict object to
configuration_data(). This is nicer because it doesn't require
repeating the name of the cfg_data object over and over.
There is one exception: the 'conf' object, where we store values
that are used directly by C code. In that case, using a dict
object is not feasible for two reasons: first of all, replacing
the set_quoted() calls would result in awkward code with a lot
of calls to format(); moreover, since code that modifies it is
sprinkled all over the place, refactoring it would probably
make things more complicated rather than simpler.
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
The current setup uses a single script that is symlinked twice
and that tries to configure bash completion for both virsh and
virt-admin, even if only one of them is installed. This also
forces us to have a -bash-completion RPM package that only
contains the tiny shared file.
Rework bash completion support so that two scripts are
generated, each one tailored to a specific command.
Since the shared script no longer exists after this change,
the corresponding RPM package becomes empty.
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Our vsh bash completion string is merely just a wrapper over
virsh/virt-admin complete (cmdComplete) - a hidden command that
uses internal readline completion to generate list of candidates.
But this means that we have to pass some additional arguments to
the helper process: e.g. connection URI and R/O flag.
Candidates are printed on a separate line each (and can contain
space), which means that when bash is reading the helper's output
into an array, it needs to split items on '\n' char - hence the
IFS=$'\n' prefix on the line executing the helper. This was
introduced in b889594a70.
But this introduced a regression - those extra arguments we might
pass are stored in a string and previously were split on a space
character (because $IFS was kept untouched and by default
contains space). But now, after the fix that's no longer the case
and thus virsh/virt-admin sees ' -r -c URI' as one argument.
The solution is to take $IFS out of the picture by storing the
extra arguments in an array instead of string.
Fixes: b889594a70
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
The way our bash completion string is that is gets user's input
and lets virsh completion code do all the work by calling 'virsh
complete -- $INPUT". The 'complete' command is a "secret",
unlisted command that exists solely for this purpose. After it
has done it's part, it prints candidates onto stdout, each
candidate on its own line, e.g. like this:
# virsh complete -- "net-u"
net-undefine
net-update
net-uuid
These strings are then stored into a bash array $A like this:
A=($($1 ${CMDLINE} complete -- "${INPUT[@]}" 2>/dev/null))
This array is then thrown back at bash completion to produce
desired output. So far so good. Except, when there is an option
with space. For instance:
# virsh complete -- start --domain ""
uefi\ duplicate
uefi
Bash interprets that as another array item because by default,
Internal Field Separator (IFS) = set of characters that bash uses
to split words at, is: space, TAB, newline. We don't want space
nor TAB. Therefore, we have to set $IFS when storing 'virsh
complete' output into the array.
Thanks to Peter who suggested it.
Resolves: https://gitlab.com/libvirt/libvirt/-/issues/116
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
We know that the bash completer automatically handle colon by preceding
it with an escape character backslash.
While our bash autompletion file vsh completes multiple items, In case
there're multiple items which have same prefix and the content of completion
items contain colon(say mac address), The vsh needs to correctly hands
the backslash which are added by bash completer, Otherwise the completion
won't be successful. This patch fixes this problem.
e.g.:
# virsh domiflist --domain VM
Interface Type Source Model MAC
-------------------------------------------------------------
vnet0 network default virtio 52:54:00:fb:7b:f5
vnet1 bridge br0 virtio 52:54:00:80:1b:21
Before:
# virsh detach-interface --domain VM --mac <TAB>
# virsh detach-interface --domain VM --mac 52\:54\:00\:<TAB><TAB>
After:
# virsh detach-interface --domain VM --mac <TAB>
# virsh detach-interface --domain VM --mac 52\:54\:00\:<TAB><TAB>
52:54:00:80:1b:21 52:54:00:fb:7b:f5
# virsh detach-interface --domain VM --mac 52\:54\:00\:
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
The only purpose of this file is to be sourced. After that one
can use completion even for their bash:
# virsh list --<TAB><TAB>
--all --inactive ...
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>