Skip to content

Commit

Permalink
lint unrecognized help parameters (Azure#6172)
Browse files Browse the repository at this point in the history
* lint unrecognized help parameters

* rm unecessary version bump

version
  • Loading branch information
williexu authored Apr 20, 2018
1 parent 1c76e3a commit 81a3b94
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
4 changes: 0 additions & 4 deletions src/command_modules/azure-cli-acs/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
Release History
===============

2.0.33
++++++
* Minor fixes

2.0.32
++++++
* remind the user that `az aks` is a preview service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
type: string
short-summary: The resource group to create the ACI container groups. Use the MC_*
resource group if it is not specified.
- name: --location
- name: --location -l
type: string
short-summary: The location to create the ACI container groups. Use the location of the MC_*
resource group if it is not specified.
Expand Down Expand Up @@ -356,7 +356,7 @@
type: string
short-summary: The resource group to create the ACI container groups. Use the MC_*
resource group if it is not specified.
- name: --location
- name: --location -l
type: string
short-summary: The location to create the ACI container groups. Use the location of the MC_*
resource group if it is not specified.
Expand Down
2 changes: 1 addition & 1 deletion src/command_modules/azure-cli-acs/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger.warn("Wheel is not available, disabling bdist_wheel hook")
cmdclass = {}

VERSION = "2.0.33"
VERSION = "2.0.32"
CLASSIFIERS = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
type: command
short-summary: Update a metric-based alert rule.
parameters:
- name: --target
short-summary: ID of the resource to target for the alert rule.
- name: --description
short-summary: Description of the rule.
- name: --condition
Expand Down
7 changes: 7 additions & 0 deletions tools/automation/cli_linter/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def get_command_parameters(self, command_name):
def get_help_entry_type(self, entry_name):
return self._all_yaml_help.get(entry_name).get('type')

def get_help_entry_parameter_names(self, entry_name):
return [param_help.get('name', None) for param_help in \
self._all_yaml_help.get(entry_name).get('parameters', [])]

def is_valid_parameter_help_name(self, entry_name, param_name):
return param_name in [param.name for param in self._loaded_help.get(entry_name).parameters]

def get_command_help(self, command_name):
return self._get_loaded_help_description(command_name)

Expand Down
14 changes: 14 additions & 0 deletions tools/automation/cli_linter/rules/help_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ def faulty_help_type_rule(linter, help_entry):
raise RuleError('Command-group should be of help-type `group`')
elif linter.get_help_entry_type(help_entry) != 'command' and help_entry in linter.commands:
raise RuleError('Command should be of help-type `command`')


@help_file_entry_rule
def unrecognized_help_parameter_rule(linter, help_entry):
if help_entry not in linter.commands:
return

param_help_names = linter.get_help_entry_parameter_names(help_entry)
violations = []
for param_help_name in param_help_names:
if not linter.is_valid_parameter_help_name(help_entry, param_help_name):
violations.append(param_help_name)
if violations:
raise RuleError('The following parameter help names are invalid: {}'.format(' | '.join(violations)))

0 comments on commit 81a3b94

Please sign in to comment.