зеркало из https://github.com/microsoft/azure-cli.git
Merge pull request #29 from johanste/commandcomplete
Fix up some of the basic command completion
This commit is contained in:
Коммит
2a60c963a1
|
@ -177,7 +177,7 @@ class ArgumentParser(object):
|
|||
show_usage = True
|
||||
|
||||
if show_completions:
|
||||
return ArgumentParser._display_completions(m, out)
|
||||
return self._display_completions(m, args, out)
|
||||
if show_usage:
|
||||
return self._display_usage(nouns, m, out)
|
||||
|
||||
|
@ -264,13 +264,26 @@ class ArgumentParser(object):
|
|||
out.flush()
|
||||
logger.debug('Expected documentation at %s', doc_file)
|
||||
|
||||
@staticmethod
|
||||
def _display_completions(noun_map, out=sys.stdout):
|
||||
completions = [k for k in noun_map if not k.startswith('$')]
|
||||
def _display_completions(self, noun_map, arguments, out=sys.stdout): # pylint: disable=no-self-use
|
||||
arguments.remove('--complete')
|
||||
|
||||
kwargs = noun_map.get('$kwargs')
|
||||
if kwargs:
|
||||
completions.extend('--' + a for a in kwargs if a)
|
||||
command_candidates = set([k for k in noun_map if not k.startswith('$')])
|
||||
if command_candidates and not arguments[-1].startswith('-'):
|
||||
command_candidates = set([c for c in command_candidates if c.startswith(arguments[-1])])
|
||||
|
||||
print('\n'.join(sorted(completions)), file=out)
|
||||
kwargs = noun_map.get('$kwargs') or []
|
||||
args_candidates = set('--' + a for a in kwargs if a)
|
||||
if arguments[-1].startswith('-'):
|
||||
# TODO: We don't have enough metadata about the command to do parameter value
|
||||
# completion (yet). This should only apply to value arguments, not flag arguments
|
||||
if arguments[-1] in args_candidates:
|
||||
args_candidates = set()
|
||||
else:
|
||||
args_candidates = set([c for c in args_candidates if c.startswith(arguments[-1])])
|
||||
else:
|
||||
args_candidates = args_candidates.difference(arguments)
|
||||
|
||||
candidates = command_candidates.union(args_candidates)
|
||||
|
||||
print('\n'.join(sorted(candidates)), file=out)
|
||||
out.flush()
|
||||
|
|
|
@ -89,7 +89,7 @@ build_operation("vm",
|
|||
(VirtualMachinesOperations.list_all, '[VirtualMachine]'),
|
||||
(VirtualMachinesOperations.list_available_sizes, '[VirtualMachineSize]'),
|
||||
(VirtualMachinesOperations.power_off, None),
|
||||
(VirtualMachinesOperations.restart, None),
|
||||
(VirtualMachinesOperations.restart, LongRunningOperation(L('Restarting VM'), L('VM Restarted'))),
|
||||
(VirtualMachinesOperations.start, LongRunningOperation(L('Starting VM'), L('VM Started'))),
|
||||
])
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче