def _show_vault_only_deprecate_message(ns): message_dict = { 'keyvault delete': Deprecated( ns.cmd.cli_ctx, message_func=lambda x: 'Warning! If you have soft-delete protection enabled on this key vault, you will ' 'not be able to reuse this key vault name until the key vault has been purged from ' 'the soft deleted state. Please see the following documentation for additional ' 'guidance.\nhttps://docs.microsoft.com/en-us/azure/key-vault/general/soft-delete-overview' ), 'keyvault key delete': Deprecated( ns.cmd.cli_ctx, message_func=lambda x: 'Warning! If you have soft-delete protection enabled on this key vault, this key ' 'will be moved to the soft deleted state. You will not be able to create a key with ' 'the same name within this key vault until the key has been purged from the ' 'soft-deleted state. Please see the following documentation for additional ' 'guidance.\nhttps://docs.microsoft.com/en-us/azure/key-vault/general/soft-delete-overview' ) } cmds = ['keyvault delete', 'keyvault key delete'] for cmd in cmds: if cmd == getattr(ns, 'command', None): print(message_dict[cmd].message, file=sys.stderr)
def add_cli_command(self, name, command_operation, **kwargs): """Register a command in command_table with command operation provided""" 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 _cli_command(self, name, operation=None, handler=None, argument_loader=None, description_loader=None, **kwargs): from knack.deprecation import Deprecated kwargs['deprecate_info'] = Deprecated.ensure_new_style_deprecation(self.cli_ctx, kwargs, 'command') if operation and not isinstance(operation, six.string_types): raise TypeError("Operation must be a string. Got '{}'".format(operation)) if handler and not callable(handler): raise TypeError("Handler must be a callable. Got '{}'".format(operation)) if bool(operation) == bool(handler): raise TypeError("Must specify exactly one of either 'operation' or 'handler'") name = ' '.join(name.split()) client_factory = kwargs.get('client_factory', None) def default_command_handler(command_args): from azure.cli.core.util import get_arg_list, augment_no_wait_handler_args from azure.cli.core.commands.client_factory import resolve_client_arg_name op = handler or self.get_op_handler(operation) op_args = get_arg_list(op) cmd = command_args.get('cmd') if 'cmd' in op_args else command_args.pop('cmd') client = client_factory(cmd.cli_ctx, command_args) if client_factory else None supports_no_wait = kwargs.get('supports_no_wait', None) if supports_no_wait: no_wait_enabled = command_args.pop('no_wait', False) augment_no_wait_handler_args(no_wait_enabled, op, command_args) if client: client_arg_name = resolve_client_arg_name(operation, kwargs) if client_arg_name in op_args: command_args[client_arg_name] = client return op(**command_args) def default_arguments_loader(): op = handler or self.get_op_handler(operation) self._apply_doc_string(op, kwargs) cmd_args = list(extract_args_from_signature(op, excluded_params=self.excluded_command_handler_args)) return cmd_args def default_description_loader(): op = handler or self.get_op_handler(operation) self._apply_doc_string(op, kwargs) return extract_full_summary_from_signature(op) kwargs['arguments_loader'] = argument_loader or default_arguments_loader kwargs['description_loader'] = description_loader or default_description_loader 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(self, name, handler or default_command_handler, **kwargs)
def _cli_command(self, name, operation=None, handler=None, argument_loader=None, description_loader=None, **kwargs): from knack.deprecation import Deprecated kwargs['deprecate_info'] = Deprecated.ensure_new_style_deprecation(self.cli_ctx, kwargs, 'command') if operation and not isinstance(operation, six.string_types): raise TypeError("Operation must be a string. Got '{}'".format(operation)) if handler and not callable(handler): raise TypeError("Handler must be a callable. Got '{}'".format(operation)) if bool(operation) == bool(handler): raise TypeError("Must specify exactly one of either 'operation' or 'handler'") name = ' '.join(name.split()) client_factory = kwargs.get('client_factory', None) def default_command_handler(command_args): from azure.cli.core.util import get_arg_list, augment_no_wait_handler_args from azure.cli.core.commands.client_factory import resolve_client_arg_name op = handler or self.get_op_handler(operation) op_args = get_arg_list(op) cmd = command_args.get('cmd') if 'cmd' in op_args else command_args.pop('cmd') client = client_factory(cmd.cli_ctx, command_args) if client_factory else None supports_no_wait = kwargs.get('supports_no_wait', None) if supports_no_wait: no_wait_enabled = command_args.pop('no_wait', False) augment_no_wait_handler_args(no_wait_enabled, op, command_args) if client: client_arg_name = resolve_client_arg_name(operation, kwargs) if client_arg_name in op_args: command_args[client_arg_name] = client return op(**command_args) def default_arguments_loader(): op = handler or self.get_op_handler(operation) self._apply_doc_string(op, kwargs) cmd_args = list(extract_args_from_signature(op, excluded_params=self.excluded_command_handler_args)) return cmd_args def default_description_loader(): op = handler or self.get_op_handler(operation) self._apply_doc_string(op, kwargs) return extract_full_summary_from_signature(op) kwargs['arguments_loader'] = argument_loader or default_arguments_loader kwargs['description_loader'] = description_loader or default_description_loader 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(self, name, handler or default_command_handler, **kwargs)
def _cli_command(self, name, operation=None, handler=None, argument_loader=None, description_loader=None, **kwargs): '''Adds a command to the command table :param name: command name ''' kwargs['deprecate_info'] = Deprecated.ensure_new_style_deprecation( self.cli_ctx, kwargs, 'command') if operation and not isinstance(operation, six.string_types): raise TypeError( "Operation must be a string. Got '{}'".format(operation)) if handler and not callable(handler): raise TypeError( "Handler must be a callable. Got '{}'".format(operation)) if bool(operation) == bool(handler): raise TypeError( "Must specify exactly one of either 'operation' or 'handler'") name = ' '.join(name.split()) client_factory = kwargs.get('client_factory', None) def default_command_handler(command_args): ''' Handler function for user commands. :param command_args: list of commandline arguments ''' # Gets the handler function from the specified operation template op = handler or self.get_op_handler( operation, operation_group=kwargs.get('operation_group')) op_args = get_arg_list(op) # Removes cmd from list of command_args. This is because the handler function # doesn't expect cmd as an argument. cmd = command_args.get( 'cmd') if 'cmd' in op_args else command_args.pop('cmd') # Gets the http client. In our case, the client is a GraphSession object. client = client_factory(cmd.cli_ctx, command_args) if client_factory else None # If a client exists, add it to the list of arguments passed to a handler function. if client: client_arg_name = resolve_client_arg_name(operation, kwargs) if client_arg_name in op_args: command_args[client_arg_name] = client return op(**command_args) def default_arguments_loader(): '''Loads handler function's arguments from operation_template ''' # Get the handler function for the specified operation template op = handler or self.get_op_handler( operation, operation_group=kwargs.get('operation_group')) # Extract command args from the handler function signature cmd_args = list( extract_args_from_signature( op, excluded_params=self.excluded_command_handler_args)) return cmd_args def default_description_loader(): '''Loads handler function's description. ''' op = handler or self.get_op_handler( operation, operation_group=kwargs.get('operation_group')) return extract_full_summary_from_signature(op) kwargs[ 'arguments_loader'] = argument_loader or default_arguments_loader kwargs[ 'description_loader'] = description_loader or default_description_loader # Adds command to command_table with it's associated command handler and loaders. self.command_table[name] = self.command_cls( self, name, handler or default_command_handler, **kwargs)