mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
cli: Strip find_inst regex from completion results
It doesn't really work with the argcompleter, so show the non-regex version of the suboption
This commit is contained in:
parent
7c835321be
commit
384607e502
@ -10,6 +10,8 @@ import os
|
||||
|
||||
# Need to do this before any tests or virtinst import
|
||||
os.environ["VIRTINST_TEST_SUITE"] = "1"
|
||||
# Need to do this before we import argcomplete
|
||||
os.environ.pop("_ARC_DEBUG", None)
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
from virtcli import cliconfig
|
||||
|
@ -1180,6 +1180,8 @@ _add_argcomplete_cmd("virt-install --disk ", "driver.copy_on_read=") # will lis
|
||||
_add_argcomplete_cmd("virt-install --disk a", "address.base")
|
||||
_add_argcomplete_cmd("virt-install --disk address.u", "address.unit")
|
||||
_add_argcomplete_cmd("virt-install --disk address.unit=foo,sg", "sgio")
|
||||
_add_argcomplete_cmd("virt-install --disk path=fooo,", "driver.cache") # will list all --disk subprops
|
||||
_add_argcomplete_cmd("virt-install --disk source.seclab", "source.seclabel.relabel") # completer should strip out regexes from results
|
||||
_add_argcomplete_cmd("virt-install --check d", "disk_size")
|
||||
_add_argcomplete_cmd("virt-install --location k", "kernel")
|
||||
_add_argcomplete_cmd("virt-install --os-variant nam", "name")
|
||||
|
@ -471,8 +471,10 @@ def _virtparser_completer(prefix, **kwargs):
|
||||
for parserclass in _get_completer_parsers():
|
||||
if kwargs['action'].dest == parserclass.cli_arg_name:
|
||||
# pylint: disable=protected-access
|
||||
for arg in sorted(parserclass._virtargs, key=lambda p: p.cliname):
|
||||
sub_options.append(arg.cliname + "=")
|
||||
for virtarg in sorted(parserclass._virtargs,
|
||||
key=lambda p: p.nonregex_cliname()):
|
||||
sub_options.append(virtarg.nonregex_cliname() + "=")
|
||||
|
||||
entered_options = prefix.split(",")
|
||||
for option in entered_options:
|
||||
pos = option.find("=")
|
||||
@ -481,19 +483,24 @@ def _virtparser_completer(prefix, **kwargs):
|
||||
return sub_options
|
||||
|
||||
|
||||
def _completer_validator(current_input, keyword_to_check_against):
|
||||
entered_options = keyword_to_check_against.split(",")
|
||||
def _completer_validator(suboption, current_input):
|
||||
"""
|
||||
:param suboption: The virtarg.cliname we are checking for a match
|
||||
:param current_input: The user typed string we are checking against.
|
||||
So if the user types '--disk path=foo,dev<TAB>',
|
||||
current_input=='path=foo,dev'
|
||||
|
||||
# e.g. for: --disk <TAB><TAB>
|
||||
if keyword_to_check_against == "":
|
||||
For debugging here, 'export _ARC_DEBUG=1'. Now exceptions/printing
|
||||
will be shown on stderr
|
||||
"""
|
||||
# e.g. for: --disk <TAB><TAB> (return all suboptions)
|
||||
if current_input == "":
|
||||
return True
|
||||
# e.g. for: --disk bu<TAB><TAB> or --disk bus=ide,<TAB><TAB>
|
||||
# or --disk bus=ide,pa<TAB><TAB>
|
||||
if (len(entered_options) >= 1 and "=" not in entered_options[-1]):
|
||||
if entered_options[-1] == "":
|
||||
return True
|
||||
else:
|
||||
return current_input.startswith(entered_options[-1])
|
||||
|
||||
# e.g. for: --disk path=foo,<TAB><TAB> (return all suboptions)
|
||||
# or: --disk path=foo,de<TAB>TAB> (return all 'de*' options)
|
||||
current_option = current_input.rsplit(",", 1)[-1]
|
||||
return suboption.startswith(current_option)
|
||||
|
||||
|
||||
def autocomplete(parser):
|
||||
@ -946,6 +953,9 @@ class _VirtCLIArgumentStatic(object):
|
||||
if self.lookup_cb == -1:
|
||||
self.lookup_cb = None
|
||||
|
||||
def nonregex_cliname(self):
|
||||
return self.cliname.replace("[0-9]*", "")
|
||||
|
||||
def match_name(self, cliname):
|
||||
"""
|
||||
Return True if the passed argument name matches this
|
||||
|
Loading…
Reference in New Issue
Block a user