diff --git a/src/command_modules/azure-cli-interactive/HISTORY.rst b/src/command_modules/azure-cli-interactive/HISTORY.rst index 0e08c591226..187a36354fa 100644 --- a/src/command_modules/azure-cli-interactive/HISTORY.rst +++ b/src/command_modules/azure-cli-interactive/HISTORY.rst @@ -6,7 +6,9 @@ Release History 0.3.20 ++++++ * Allow interactive completers to function with positional arguments. -* More user-friendly output when users type '\' +* More user-friendly output when users type '\'. +* Fix completions for parameters with no help. +* Fix descriptions for command-groups. 0.3.19 ++++++ diff --git a/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/app.py b/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/app.py index 4b423694994..704f4f08ed1 100644 --- a/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/app.py +++ b/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/app.py @@ -285,22 +285,23 @@ def generate_help_text(self): rows, _ = get_window_dim() rows = int(rows) - if not self.completer: - return param_descrip, example param_args = self.completer.leftover_args last_word = self.completer.unfinished_word command = self.completer.current_command new_command = ' '.join([command, last_word]).strip() - if not self.completer.complete_command and new_command in self.completer.command_param_info: + + if not self.completer.complete_command and new_command in self.completer.command_description: command = new_command - param = param_args[-1] if param_args else '' - param = last_word if last_word.startswith('-') else param + # get command/group help + if self.completer and command in self.completer.command_description: + self.description_docs = u'{}'.format(self.completer.command_description[command]) + # get parameter help if full command if self.completer and command in self.completer.command_param_info: - self.description_docs = u'{}'.format( - self.completer.command_description[command]) + param = param_args[-1] if param_args else '' + param = last_word if last_word.startswith('-') else param if param in self.completer.command_param_info[command] and self.completer.has_description( command + " " + param): diff --git a/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/az_completer.py b/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/az_completer.py index 5775a79d5ad..6ab1e694217 100644 --- a/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/az_completer.py +++ b/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/az_completer.py @@ -45,7 +45,7 @@ def __init__(self, shell_ctx, commands, global_params=True): self.started = False # dictionary of command to descriptions - self.command_description = None + self.command_description = {} # a list of all the possible parameters self.completable_param = None # the command tree diff --git a/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/gather_commands.py b/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/gather_commands.py index 5957b5021e7..09555e506c6 100644 --- a/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/gather_commands.py +++ b/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/azclishell/gather_commands.py @@ -137,8 +137,7 @@ def _gather_from_files(self, config): command_params = data[command].get('parameters', {}) for param in command_params: - if command_params[param]['help'] and \ - '==SUPPRESS==' not in command_params[param]['help']: + if '==SUPPRESS==' not in command_params[param]['help']: param_aliases = set() for par in command_params[param]['name']: diff --git a/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/tests/latest/test_completion.py b/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/tests/latest/test_completion.py index 0c4e3d4bb2b..89767addd4d 100644 --- a/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/tests/latest/test_completion.py +++ b/src/command_modules/azure-cli-interactive/azure/cli/command_modules/interactive/tests/latest/test_completion.py @@ -18,7 +18,15 @@ class CompletionTest(unittest.TestCase): - """ tests the completion generator """ + def __init__(self, methodName): + super(CompletionTest, self).__init__(methodName) + with mock.patch.object(Configuration, 'get_help_files', lambda _: 'help_dump_test.json'): + with mock.patch.object(Configuration, 'get_config_dir', lambda _: TEST_DIR): + shell_ctx = AzInteractiveShell(TestCli(), None) + self.completer = shell_ctx.completer + self.shell_ctx = shell_ctx + + # tests the completion generator def verify_completions(self, generated_completions, expected_completions, start_position, all_completions_expected=True, unexpected_completions=None): for completion in generated_completions: @@ -33,16 +41,7 @@ def verify_completions(self, generated_completions, expected_completions, start_ self.assertEqual(completion.start_position, start_position) self.assertFalse(expected_completions) - def init_completer(self): - with mock.patch.object(Configuration, 'get_help_files', lambda _: 'help_dump_test.json'): - with mock.patch.object(Configuration, 'get_config_dir', lambda _: TEST_DIR): - shell_ctx = AzInteractiveShell(TestCli(), None) - self.completer = shell_ctx.completer - def test_command_completion(self): - # tests some azure commands - self.init_completer() - # initial completions doc = Document(u' ') gen = self.completer.get_completions(doc, None) @@ -80,9 +79,6 @@ def test_command_completion(self): self.verify_completions(gen, completions, 0) def test_param_completion(self): - # tests some azure params - self.init_completer() - # 'az -h' doc = Document(u'-') gen = self.completer.get_completions(doc, None) @@ -120,6 +116,12 @@ def test_param_completion(self): completions = set(['--subnet', '--subnet-address-prefix']) self.verify_completions(gen, completions, -8) + # test params with no help + doc = Document(u'vmss create --upgrade-policy-mo') + gen = self.completer.get_completions(doc, None) + completions = set(['--upgrade-policy-mode']) + self.verify_completions(gen, completions, -19) + # test duplicated parameters expected = set() doc = Document(u'vmss create --name Bob --n') @@ -128,10 +130,10 @@ def test_param_completion(self): self.verify_completions(gen, expected, -3, all_completions_expected=False, unexpected_completions=not_expected) # test duplicated parameter alias - doc = Document(u'vmss create --name Bob -n') + doc = Document(u'vmss create --name Bob -') gen = self.completer.get_completions(doc, None) not_expected = set(['-n']) - self.verify_completions(gen, expected, -2, all_completions_expected=False, unexpected_completions=not_expected) + self.verify_completions(gen, expected, -1, all_completions_expected=False, unexpected_completions=not_expected) # test displayed help doc = Document(u'vm create -g') diff --git a/src/command_modules/azure-cli-monitor/azure/cli/command_modules/monitor/_help.py b/src/command_modules/azure-cli-monitor/azure/cli/command_modules/monitor/_help.py index 92bb8ff0062..aa3c0090ada 100644 --- a/src/command_modules/azure-cli-monitor/azure/cli/command_modules/monitor/_help.py +++ b/src/command_modules/azure-cli-monitor/azure/cli/command_modules/monitor/_help.py @@ -205,8 +205,6 @@ parameters: - name: --name -n short-summary: The name of the log profile. - - name: --location -l - short-summary: - name: --locations short-summary: Space-separated list of regions for which Activity Log events should be stored. - name: --categories