Skip to content
Merged
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
2 changes: 2 additions & 0 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
<Compile Include="command_modules\azure-cli-appservice\azure\cli\__init__.py" />
<Compile Include="command_modules\azure-cli-appservice\azure\__init__.py" />
<Compile Include="command_modules\azure-cli-appservice\setup.py" />
<Compile Include="command_modules\azure-cli-batch\azure\cli\command_modules\batch\tests\test_batch_commands.py" />
<Compile Include="command_modules\azure-cli-batch\azure\cli\command_modules\batch\tests\test_batch_data_plane_commands.py" />
<Compile Include="command_modules\azure-cli-batch\azure\cli\command_modules\batch\tests\test_batch_pool_commands.py" />
<Compile Include="command_modules\azure-cli-batch\azure\cli\command_modules\batch\_command_type.py" />
<Compile Include="command_modules\azure-cli-cloud\azure\cli\command_modules\cloud\commands.py" />
<Compile Include="command_modules\azure-cli-cloud\azure\cli\command_modules\cloud\custom.py" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@
FilesCompleter,
DirectoriesCompleter)

from msrest.exceptions import DeserializationError

from . import _validators as validators
from azure.cli.core.commands import (
FORCE_PARAM_NAME,
command_table,
command_module_map,
CliCommand,
CliCommandArgument,
get_op_handler)
get_op_handler,
_user_confirmed)
from azure.cli.core._util import CLIError
from azure.cli.core._config import az_config
from azure.cli.core.commands._introspection import (
extract_full_summary_from_signature,
extract_args_from_signature)
from azure.cli.core.commands.parameters import file_type

# TODO: Enum choice lists


_CLASS_NAME = re.compile(r"<(.*?)>") # Strip model name from class docstring
Expand Down Expand Up @@ -101,9 +109,9 @@ def find_param_type(model, param):
:returns: str
"""
# Search for the :type param_name: in the docstring
pattern = r":type {}:(.*?)\n(\s*:param |\s*:rtype:|\s*:raises:|\"\"\")".format(param)
pattern = r":type {}:(.*?)\n(\s*:param |\s*:rtype:|\s*:raises:|\s*\"{{3}})".format(param)
param_type = re.search(pattern, model.__doc__, re.DOTALL)
return re.sub(r"\n\s*", " ", param_type.group(1).strip())
return re.sub(r"\n\s*", "", param_type.group(1).strip())


def find_param_help(model, param):
Expand All @@ -115,7 +123,7 @@ def find_param_help(model, param):
# Search for :param param_name: in the docstring
pattern = r":param {}:(.*?)\n\s*:type ".format(param)
param_doc = re.search(pattern, model.__doc__, re.DOTALL)
return re.sub(r"\n\s*", "", param_doc.group(1).strip())
return re.sub(r"\n\s*", " ", param_doc.group(1).strip())


def find_return_type(model):
Expand Down Expand Up @@ -261,12 +269,16 @@ def deserialize_json(self, client, kwargs, json_obj):
:param dict kwargs: The request kwargs
:param dict json_obj: The loaded JSON content
"""
#TODO: catch exception
kwargs[self._request_param['name']] = client._deserialize( #pylint:disable=W0212
self._request_param['model'], json_obj)
if kwargs[self._request_param['name']] is None:
message = "Failed to deserialized JSON file into object {}"
message = "Failed to deserialized JSON file into object {}"
try:
kwargs[self._request_param['name']] = client._deserialize( #pylint:disable=W0212
self._request_param['model'], json_obj)
except DeserializationError as error:
message += ": {}".format(error)
raise ValueError(message.format(self._request_param['model']))
else:
if kwargs[self._request_param['name']] is None:
raise ValueError(message.format(self._request_param['model']))

def queue_argument(self, name=None, path=None, root=None, #pylint:disable=too-many-arguments
options=None, type=None, dependencies=None): #pylint:disable=W0622
Expand Down Expand Up @@ -399,6 +411,7 @@ def __init__(self, module_name, name, operation, factory, transform_result, #pyl
self.ignore.extend(ignore)
self.parser = None
self.validator = validator
self.confirmation = 'delete' in operation

# The name of the request options parameter
self._options_param = format_options_name(operation)
Expand All @@ -413,6 +426,9 @@ def _execute_command(kwargs):
from msrest.paging import Paged
from msrest.exceptions import ValidationError, ClientRequestError
from azure.batch.models import BatchErrorException
if self._cancel_operation(kwargs):
raise CLIError('Operation cancelled.')

try:
client = factory(kwargs)
self._build_options(kwargs)
Expand Down Expand Up @@ -483,6 +499,17 @@ def _execute_command(kwargs):
get_op_handler(operation))
)

def _cancel_operation(self, kwargs):
"""Whether to cancel the current operation because user
declined the confirmation prompt.
:param dict kwargs: The request arguments.
:returns: bool
"""
return self.confirmation \
and not kwargs.get(FORCE_PARAM_NAME) \
and not az_config.getboolean('core', 'disable_confirm_prompt', fallback=False) \
and not _user_confirmed(self.confirmation, kwargs)

def _build_parameters(self, path, kwargs, param, value):
"""Recursively build request parameter dictionary from command line args.
:param str arg_path: Current parameter namespace.
Expand Down Expand Up @@ -670,6 +697,7 @@ def _load_transformed_arguments(self, handler):
options_list=[arg_name(param)],
required=False,
default=None,
type=file_type,
completer=FilesCompleter(),
help=docstring))
elif arg[0] not in self.ignore:
Expand All @@ -682,8 +710,17 @@ def _load_transformed_arguments(self, handler):
required=True,
default=None,
completer=DirectoriesCompleter(),
type=file_type,
validator=validators.validate_file_destination,
help=docstring))
if self.confirmation:
param = FORCE_PARAM_NAME
docstring = 'Do not prompt for confirmation.'
yield (param, CliCommandArgument(param,
options_list=[arg_name(param)],
required=False,
action='store_true',
help=docstring))


def cli_data_plane_command(name, operation, client_factory, transform=None, #pylint:disable=too-many-arguments
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "azure-cli-test-json",
"vmSize": "small",
"cloudServiceConfiguration": {
"osFamily": "4",
"targetOSVersion": "*"
}
"targetDedicated": 2,
"resizeTimeout": "PT15M",
"environmentSettings": [
{
"name": "TEST_ENV",
"value": "TEST_VALUE"
},
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"id": "azure-cli-test-json",
"vmSize": "small",
"cloudServiceConfiguration": {
"osFamily": "4",
"targetOSVersion": "*"
},
"targetDedicated": 2,
"resizeTimeout": "PT15M",
"environmentSettings": [
{
"name": "TEST_ENV",
"value": "TEST_VALUE"
}
],
"startTask": {
"commandLine": "cmd /c echo test",
"waitForSuccess": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"startTask": {
"commandLine": "cmd /c echo updated",
"waitForSuccess": true
},
"certificateReferences": {},
"metadata": {},
"applicationPackageReferences": {}
}
Loading