Skip to content
545 changes: 545 additions & 0 deletions doc/generating_configuration_guidance.md

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/azure-cli-core/azure/cli/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ def command_group(self, group_name, command_type=None, **kwargs):
def argument_context(self, scope, **kwargs):
return self._argument_context_cls(self, scope, **kwargs)

# keyvault and batch are using this function
def _cli_command(self, name, operation=None, handler=None, argument_loader=None, description_loader=None, **kwargs):

from knack.deprecation import Deprecated
Expand Down Expand Up @@ -833,6 +834,30 @@ def default_description_loader():
handler or default_command_handler,
**kwargs)

def add_cli_command(self, name, command_operation, **kwargs):
from knack.deprecation import Deprecated
from .commands.command_operation import BaseCommandOperation
if not issubclass(type(command_operation), BaseCommandOperation):
raise TypeError("CommandOperation must be an instance of subclass of BaseCommandOperation."
" Got instance of '{}'".format(type(command_operation)))

kwargs['deprecate_info'] = Deprecated.ensure_new_style_deprecation(self.cli_ctx, kwargs, 'command')

name = ' '.join(name.split())

if self.supported_api_version(resource_type=kwargs.get('resource_type'),
min_api=kwargs.get('min_api'),
max_api=kwargs.get('max_api'),
operation_group=kwargs.get('operation_group')):
self._populate_command_group_table_with_subgroups(' '.join(name.split()[:-1]))
self.command_table[name] = self.command_cls(loader=self,
name=name,
handler=command_operation.handler,
arguments_loader=command_operation.arguments_loader,
description_loader=command_operation.description_loader,
command_operation=command_operation,
**kwargs)

def get_op_handler(self, operation, operation_group=None):
""" Import and load the operation handler """
# Patch the unversioned sdk path to include the appropriate API version for the
Expand Down
66 changes: 50 additions & 16 deletions src/azure-cli-core/azure/cli/core/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,12 @@ def update(self, other=None, **kwargs):
class AzCommandGroup(CommandGroup):

def __init__(self, command_loader, group_name, **kwargs):
"""
:param command_loader: The command loader that commands will be registered into
:type command_loader: azure.cli.core.AzCommandsLoader
:param group_name: The name of the group of commands in the command hierarchy
:type group_name: str
"""
merged_kwargs = self._merge_kwargs(kwargs, base_kwargs=command_loader.module_kwargs)
operations_tmpl = merged_kwargs.pop('operations_tmpl', None)
super(AzCommandGroup, self).__init__(command_loader, group_name,
Expand Down Expand Up @@ -1247,16 +1253,24 @@ def custom_command(self, name, method_name=None, **kwargs):
return self._command(name, method_name=method_name, custom_command=True, **kwargs)

def _command(self, name, method_name, custom_command=False, **kwargs):
from .command_operation import CommandOperation

self._check_stale()
merged_kwargs = self._flatten_kwargs(kwargs, get_command_type_kwarg(custom_command))
self._apply_tags(merged_kwargs, kwargs, name)

operations_tmpl = merged_kwargs['operations_tmpl']
command_name = '{} {}'.format(self.group_name, name) if self.group_name else name
self.command_loader._cli_command(command_name, # pylint: disable=protected-access
operation=operations_tmpl.format(method_name),
**merged_kwargs)
operation = operations_tmpl.format(method_name)

command_name = '{} {}'.format(self.group_name, name) if self.group_name else name
command_operation = CommandOperation(
ctx=self.command_loader,
operation=operation,
**merged_kwargs
)
self.command_loader.add_cli_command(command_name,
command_operation=command_operation,
**merged_kwargs)
return command_name

# pylint: disable=no-self-use
Expand Down Expand Up @@ -1286,7 +1300,7 @@ def generic_update_command(self, name, getter_name='get', getter_type=None,
setter_name='create_or_update', setter_type=None, setter_arg_name='parameters',
child_collection_prop_name=None, child_collection_key='name', child_arg_name='item_name',
custom_func_name=None, custom_func_type=None, **kwargs):
from azure.cli.core.commands.arm import _cli_generic_update_command
from azure.cli.core.commands.command_operation import GenericUpdateCommandOperation
self._check_stale()
merged_kwargs = self._flatten_kwargs(kwargs, get_command_type_kwarg())
merged_kwargs_custom = self._flatten_kwargs(kwargs, get_command_type_kwarg(custom_command=True))
Expand All @@ -1296,17 +1310,21 @@ def generic_update_command(self, name, getter_name='get', getter_type=None,
setter_op = self._resolve_operation(merged_kwargs, setter_name, setter_type)
custom_func_op = self._resolve_operation(merged_kwargs_custom, custom_func_name, custom_func_type,
custom_command=True) if custom_func_name else None
_cli_generic_update_command(
self.command_loader,
'{} {}'.format(self.group_name, name),
command_name = '{} {}'.format(self.group_name, name) if self.group_name else name
command_operation = GenericUpdateCommandOperation(
ctx=self.command_loader,
getter_op=getter_op,
setter_op=setter_op,
setter_arg_name=setter_arg_name,
custom_function_op=custom_func_op,
child_collection_prop_name=child_collection_prop_name,
child_collection_key=child_collection_key,
child_arg_name=child_arg_name,
**merged_kwargs)
**merged_kwargs
)
self.command_loader.add_cli_command(command_name,
command_operation=command_operation,
**merged_kwargs)

def wait_command(self, name, getter_name='get', **kwargs):
self._wait_command(name, getter_name=getter_name, custom_command=False, **kwargs)
Expand All @@ -1318,16 +1336,24 @@ def generic_wait_command(self, name, getter_name='get', getter_type=None, **kwar
self._wait_command(name, getter_name=getter_name, getter_type=getter_type, **kwargs)

def _wait_command(self, name, getter_name='get', getter_type=None, custom_command=False, **kwargs):
from azure.cli.core.commands.arm import _cli_wait_command
from azure.cli.core.commands.command_operation import WaitCommandOperation
self._check_stale()
merged_kwargs = self._flatten_kwargs(kwargs, get_command_type_kwarg(custom_command))
self._apply_tags(merged_kwargs, kwargs, name)

if getter_type:
merged_kwargs = _merge_kwargs(getter_type.settings, merged_kwargs, CLI_COMMAND_KWARGS)
getter_op = self._resolve_operation(merged_kwargs, getter_name, getter_type, custom_command=custom_command)
_cli_wait_command(self.command_loader, '{} {}'.format(self.group_name, name), getter_op=getter_op,
custom_command=custom_command, **merged_kwargs)

command_name = '{} {}'.format(self.group_name, name) if self.group_name else name
command_operation = WaitCommandOperation(
ctx=self.command_loader,
operation=getter_op,
**merged_kwargs
)
self.command_loader.add_cli_command(command_name,
command_operation=command_operation,
**merged_kwargs)

def show_command(self, name, getter_name='get', **kwargs):
self._show_command(name, getter_name=getter_name, custom_command=False, **kwargs)
Expand All @@ -1336,16 +1362,24 @@ def custom_show_command(self, name, getter_name='get', **kwargs):
self._show_command(name, getter_name=getter_name, custom_command=True, **kwargs)

def _show_command(self, name, getter_name='get', getter_type=None, custom_command=False, **kwargs):
from azure.cli.core.commands.arm import _cli_show_command
from azure.cli.core.commands.command_operation import ShowCommandOperation
self._check_stale()
merged_kwargs = self._flatten_kwargs(kwargs, get_command_type_kwarg(custom_command))
self._apply_tags(merged_kwargs, kwargs, name)

if getter_type:
merged_kwargs = _merge_kwargs(getter_type.settings, merged_kwargs, CLI_COMMAND_KWARGS)
getter_op = self._resolve_operation(merged_kwargs, getter_name, getter_type, custom_command=custom_command)
_cli_show_command(self.command_loader, '{} {}'.format(self.group_name, name), getter_op=getter_op,
custom_command=custom_command, **merged_kwargs)
operation = self._resolve_operation(merged_kwargs, getter_name, getter_type, custom_command=custom_command)

command_name = '{} {}'.format(self.group_name, name) if self.group_name else name
command_operation = ShowCommandOperation(
ctx=self.command_loader,
operation=operation,
**merged_kwargs
)
self.command_loader.add_cli_command(command_name,
command_operation=command_operation,
**merged_kwargs)

def _apply_tags(self, merged_kwargs, kwargs, command_name):
# don't inherit deprecation or preview info from command group
Expand Down
Loading