Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/azure-cli-core/azure/cli/core/commands/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ def get_resource_groups(cli_ctx):
return list(rcf.resource_groups.list())


def get_json_query_type(query='id'):
def json_query_type(string):
import collections
import json
import jmespath
from jmespath.exceptions import JMESPathError
try:
result = jmespath.search(query, json.loads(string), jmespath.Options(collections.OrderedDict))
return result
except (json.JSONDecodeError, JMESPathError):
return string
return json_query_type


@Completer
def get_resource_group_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument
result = get_resource_groups(cmd.cli_ctx)
Expand Down
5 changes: 3 additions & 2 deletions src/azure-cli/azure/cli/command_modules/storage/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from azure.cli.core.profiles import ResourceType
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from azure.cli.core.commands.parameters import (tags_type, file_type, get_location_type, get_enum_type,
get_three_state_flag)
get_three_state_flag, get_json_query_type)

from ._validators import (get_datetime_type, validate_metadata, get_permission_validator, get_permission_help_string,
resource_type_type, services_type, validate_entity, validate_select, validate_blob_type,
Expand Down Expand Up @@ -329,7 +329,8 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
from ._validators import validate_subnet
c.argument('account_name', acct_name_type, id_part=None)
c.argument('ip_address', help='IPv4 address or CIDR range.')
c.argument('subnet', help='Name or ID of subnet. If name is supplied, `--vnet-name` must be supplied.')
c.argument('subnet', type=get_json_query_type(),
help='Name or ID of subnet. If name is supplied, `--vnet-name` must be supplied.')
c.argument('vnet_name', help='Name of a virtual network.', validator=validate_subnet)
c.argument('action', help='The action of virtual network rule.')

Expand Down