How to use the knack.arguments.CLICommandArgument function in knack

To help you get started, we’ve selected a few knack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / batch / _command_type.py View on Github external
self._load_options_model(handler)
        args = []
        for arg in extract_args_from_signature(handler, excluded_params=EXCLUDED_PARAMS):
            arg_type = find_param_type(handler, arg[0])
            if arg[0] == self._options_param:
                for option_arg in self._process_options():
                    args.append(option_arg)
            elif arg_type.startswith("str or"):
                docstring = find_param_help(handler, arg[0])
                choices = []
                values_index = docstring.find(' Possible values include')
                if values_index >= 0:
                    choices = docstring[values_index + 25:].split(', ')
                    choices = [enum_value(c) for c in choices if enum_value(c) != "'unmapped'"]
                    docstring = docstring[0:values_index]
                args.append(((arg[0], CLICommandArgument(arg[0],
                                                         options_list=[arg_name(arg[0])],
                                                         required=False,
                                                         default=None,
                                                         choices=choices,
                                                         help=docstring))))
            elif arg_type.startswith("~"):  # TODO: could add handling for enums
                param_type = class_name(arg_type)
                self.parser.set_request_param(arg[0], param_type)
                param_model = _load_model(param_type)
                self._flatten_object(arg[0], param_model)
                for flattened_arg in self.parser.compile_args():
                    args.append(flattened_arg)
                param = 'json_file'
                docstring = "A file containing the {} specification in JSON " \
                            "(formatted to match the respective REST API body). " \
                            "If this parameter is specified, all '{} Arguments'" \
github Azure / azure-cli / src / azure-cli-core / azure / cli / core / commands / arm.py View on Github external
group_name = 'Generic Update'
        arguments['properties_to_set'] = CLICommandArgument(
            'properties_to_set', options_list=['--set'], nargs='+',
            action=OrderedArgsAction, default=[],
            help='Update an object by specifying a property path and value to set.  Example: {}'.format(set_usage),
            metavar='KEY=VALUE', arg_group=group_name
        )
        arguments['properties_to_add'] = CLICommandArgument(
            'properties_to_add', options_list=['--add'], nargs='+',
            action=OrderedArgsAction, default=[],
            help='Add an object to a list of objects by specifying a path and '
                 'key value pairs.  Example: {}'.format(add_usage),
            metavar='LIST KEY=VALUE', arg_group=group_name
        )
        arguments['properties_to_remove'] = CLICommandArgument(
            'properties_to_remove', options_list=['--remove'], nargs='+',
            action=OrderedArgsAction, default=[],
            help='Remove a property or an element from a list.  Example: {}'.format(remove_usage),
            metavar='LIST INDEX', arg_group=group_name
        )
        arguments['force_string'] = CLICommandArgument(
            'force_string', action='store_true', arg_group=group_name,
            help="When using 'set' or 'add', preserve string literals instead of attempting to convert to JSON."
        )
        return [(k, v) for k, v in arguments.items()]
github microsoft / knack / knack / commands.py View on Github external
def add_argument(self, param_name, *option_strings, **kwargs):
        dest = kwargs.pop('dest', None)
        argument = CLICommandArgument(dest or param_name, options_list=option_strings, **kwargs)
        self.arguments[param_name] = argument
github Azure / azure-cli / src / azure-cli-core / azure / cli / core / commands / arm.py View on Github external
def generic_wait_arguments_loader():
        cmd_args = get_arguments_loader(context, getter_op, operation_group=kwargs.get('operation_group'))

        group_name = 'Wait Condition'
        cmd_args['timeout'] = CLICommandArgument(
            'timeout', options_list=['--timeout'], default=3600, arg_group=group_name, type=int,
            help='maximum wait in seconds'
        )
        cmd_args['interval'] = CLICommandArgument(
            'interval', options_list=['--interval'], default=30, arg_group=group_name, type=int,
            help='polling interval in seconds'
        )
        cmd_args['deleted'] = CLICommandArgument(
            'deleted', options_list=['--deleted'], action='store_true', arg_group=group_name,
            help='wait until deleted'
        )
        cmd_args['created'] = CLICommandArgument(
            'created', options_list=['--created'], action='store_true', arg_group=group_name,
            help="wait until created with 'provisioningState' at 'Succeeded'"
        )
        cmd_args['updated'] = CLICommandArgument(
            'updated', options_list=['--updated'], action='store_true', arg_group=group_name,
            help="wait until updated with provisioningState at 'Succeeded'"
        )
        cmd_args['exists'] = CLICommandArgument(
github Azure / azure-cli / src / azure-cli-core / azure / cli / core / commands / parameters.py View on Github external
# super(AzArgumentContext, self).extra(dest, **merged_kwargs)
            from knack.arguments import CLICommandArgument
            self._check_stale()
            if not self._applicable():
                return

            if self.command_scope in self.command_loader.command_group_table:
                raise ValueError("command authoring error: extra argument '{}' cannot be registered to a group-level "
                                 "scope '{}'. It must be registered to a specific command.".format(
                                     dest, self.command_scope))

            deprecate_action = self._handle_deprecations(dest, **merged_kwargs)
            if deprecate_action:
                merged_kwargs['action'] = deprecate_action
            merged_kwargs.pop('dest', None)
            self.command_loader.extra_argument_registry[self.command_scope][dest] = CLICommandArgument(
                dest, **merged_kwargs)
github noelbundick / azure-cli-extension-noelbundick / src / noelbundick / azext_noelbundick / self_destruct.py View on Github external
def self_destruct_add_parameters(cli_ctx, **kwargs):
    from knack.arguments import CLICommandArgument
    command_table = cli_ctx.invocation.commands_loader.command_table

    if not command_table:
        return

    create_commands = [v for k, v in command_table.items() if 'create' in k]
    if create_commands:
        command = create_commands[0]
        command.arguments['self_destruct'] = CLICommandArgument('self_destruct', 
                                        options_list=['--self-destruct'],
                                        arg_group='Self Destruct (noelbundick)',
                                        help='How long to wait until deletion. You can specify durations like 1d, 6h, 2h30m, 30m, etc')
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / batch / _command_type.py View on Github external
self._head_cmd = True
        if self.confirmation:
            param = CONFIRM_PARAM_NAME
            docstring = 'Do not prompt for confirmation.'
            args.append((param, CLICommandArgument(param,
                                                   options_list=['--yes', '-y'],
                                                   required=False,
                                                   action='store_true',
                                                   help=docstring)))
        auth_group_name = 'Batch Account'
        args.append(('cmd', CLICommandArgument('cmd', action=IgnoreAction)))
        args.append(('account_name', CLICommandArgument(
            'account_name', options_list=['--account-name'], required=False, default=None,
            validator=validators.validate_client_parameters, arg_group=auth_group_name,
            help='Batch account name. Alternatively, set by environment variable: AZURE_BATCH_ACCOUNT')))
        args.append(('account_key', CLICommandArgument(
            'account_key', options_list=['--account-key'], required=False, default=None, arg_group=auth_group_name,
            help='Batch account key. Alternatively, set by environment variable: AZURE_BATCH_ACCESS_KEY')))
        args.append(('account_endpoint', CLICommandArgument(
            'account_endpoint', options_list=['--account-endpoint'], required=False,
            default=None, arg_group=auth_group_name,
            help='Batch service endpoint. Alternatively, set by environment variable: AZURE_BATCH_ENDPOINT')))
        return args
github Azure / azure-cli / src / azure-cli-core / azure / cli / core / commands / arm.py View on Github external
def generic_wait_arguments_loader():
        cmd_args = get_arguments_loader(context, getter_op, operation_group=kwargs.get('operation_group'))

        group_name = 'Wait Condition'
        cmd_args['timeout'] = CLICommandArgument(
            'timeout', options_list=['--timeout'], default=3600, arg_group=group_name, type=int,
            help='maximum wait in seconds'
        )
        cmd_args['interval'] = CLICommandArgument(
            'interval', options_list=['--interval'], default=30, arg_group=group_name, type=int,
            help='polling interval in seconds'
        )
        cmd_args['deleted'] = CLICommandArgument(
            'deleted', options_list=['--deleted'], action='store_true', arg_group=group_name,
            help='wait until deleted'
        )
        cmd_args['created'] = CLICommandArgument(
            'created', options_list=['--created'], action='store_true', arg_group=group_name,
            help="wait until created with 'provisioningState' at 'Succeeded'"
        )
        cmd_args['updated'] = CLICommandArgument(