diff --git a/src/azure/cli/_argparse.py b/src/azure/cli/_argparse.py index 70abf3e3b56..5a3b07d8d39 100644 --- a/src/azure/cli/_argparse.py +++ b/src/azure/cli/_argparse.py @@ -175,7 +175,7 @@ def not_global(a): 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) @@ -253,13 +253,26 @@ def _display_usage(self, nouns, noun_map, out=sys.stdout): 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() diff --git a/src/azure/cli/commands/vm.py b/src/azure/cli/commands/vm.py index 11d4bb37cc2..28f2f077c42 100644 --- a/src/azure/cli/commands/vm.py +++ b/src/azure/cli/commands/vm.py @@ -89,7 +89,7 @@ def _compute_client_factory(): (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'))), ])