Skip to content

Commit

Permalink
[ARM] Fix az resource list cannot use tag when there is a default loc…
Browse files Browse the repository at this point in the history
…ation (#11787)

* Improve the error message of the conflict between tag and other filter conditions for az resource list
  • Loading branch information
zhoxing-ms authored Jan 30, 2020
1 parent 55a0a0d commit 983134b
Show file tree
Hide file tree
Showing 4 changed files with 768 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Release History

* Fix issue #11658: `az group export` command does not support `--query` and `--output` parameters
* Fix issue #10279: The exit code of `az group deployment validate` is 0 when the verification fails
* Fix issue #9916: Improve the error message of the conflict between tag and other filter conditions for `az resource list` command

**Azure Red Hat OpenShift**

Expand Down
17 changes: 14 additions & 3 deletions src/azure-cli/azure/cli/command_modules/resource/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,20 @@ def _deploy_arm_template_subscription_scope(cli_ctx,
def _list_resources_odata_filter_builder(resource_group_name=None, resource_provider_namespace=None,
resource_type=None, name=None, tag=None, location=None):
"""Build up OData filter string from parameters """
if tag is not None:
if resource_group_name:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--resource-group\''
'(If the default value for resource group is set, please use \'az configure --defaults group=""\' command to clear it first)')
if resource_provider_namespace:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--namespace\'')
if resource_type:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--resource-type\'')
if name:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--name\'')
if location:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--location\''
'(If the default value for location is set, please use \'az configure --defaults location=""\' command to clear it first)')

filters = []

if resource_group_name:
Expand Down Expand Up @@ -537,9 +551,6 @@ def _list_resources_odata_filter_builder(resource_group_name=None, resource_prov
raise CLIError('--namespace also requires --resource-type')

if tag:
if name or location:
raise IncorrectUsageError('you cannot use the tag filter with other filters')

tag_name = list(tag.keys())[0] if isinstance(tag, dict) else tag
tag_value = tag[tag_name] if isinstance(tag, dict) else ''
if tag_name:
Expand Down
Loading

0 comments on commit 983134b

Please sign in to comment.