Ejemplo n.º 1
0
def register_commands():
    from cloudify_cli.config.parser_config import parser_config

    parser_conf = parser_config()
    parser = argparse.ArgumentParser(description=parser_conf["description"])

    # Direct arguments for the 'cfy' command (like -v)
    for argument_name, argument in parser_conf["arguments"].iteritems():
        parser.add_argument(argument_name, **argument)

    subparsers = parser.add_subparsers(title="Commands", metavar="")

    for command_name, command in parser_conf["commands"].iteritems():

        if "sub_commands" in command:

            # Add sub commands. Such as 'cfy blueprints list',
            # 'cfy deployments create' ...
            controller_help = command["help"]
            controller_parser = subparsers.add_parser(command_name, help=controller_help)
            controller_subparsers = controller_parser.add_subparsers(
                title="Commands",
                metavar=(" " * (constants.HELP_TEXT_COLUMN_BUFFER + longest_command_length(command["sub_commands"]))),
            )
            for controller_sub_command_name, controller_sub_command in command["sub_commands"].iteritems():
                register_command(controller_subparsers, controller_sub_command_name, controller_sub_command)
        else:

            # Add direct commands. Such as 'cfy status', 'cfy ssh' ...
            register_command(subparsers, command_name, command)

    return parser
Ejemplo n.º 2
0
def register_commands():

    from cloudify_cli.config.parser_config import parser_config
    parser_conf = parser_config()
    parser = argparse.ArgumentParser(description=parser_conf['description'])

    # Direct arguments for the 'cfy' command (like -v)
    for argument_name, argument in parser_conf['arguments'].iteritems():
        parser.add_argument(argument_name, **argument)

    subparsers = parser.add_subparsers()
    for command_name, command in parser_conf['commands'].iteritems():

        if 'sub_commands' in command:

            # Add sub commands. Such as 'cfy blueprints list',
            # 'cfy deployments create' ...
            controller_help = command['help']
            controller_parser = subparsers.add_parser(
                command_name, help=controller_help
            )
            controller_subparsers = controller_parser.add_subparsers()
            for controller_sub_command_name, controller_sub_command in \
                    command['sub_commands'].iteritems():
                register_command(controller_subparsers,
                                 controller_sub_command_name,
                                 controller_sub_command)
        else:

            # Add direct commands. Such as 'cfy status', 'cfy ssh' ...
            register_command(subparsers, command_name, command)

    return parser
Ejemplo n.º 3
0
 def test_list_sort_default(self):
     for r in self.resources_types:
         self._set_mock_list(
             r, parser_config()["commands"][r]["sub_commands"]["list"]["arguments"]["-s,--sort-by"]["default"]
         )
         cli_runner.run_cli("cfy {0} list".format(r))
     self.assertEqual(len(self.resources_types), self.count_mock_calls)
Ejemplo n.º 4
0
def register_commands():

    from cloudify_cli.config.parser_config import parser_config
    parser_conf = parser_config()
    parser = argparse.ArgumentParser(description=parser_conf['description'])

    # Direct arguments for the 'cfy' command (like -v)
    for argument_name, argument in parser_conf['arguments'].iteritems():
        parser.add_argument(argument_name, **argument)

    subparsers = parser.add_subparsers()
    for command_name, command in parser_conf['commands'].iteritems():

        if 'sub_commands' in command:

            # Add sub commands. Such as 'cfy blueprints list',
            # 'cfy deployments create' ...
            controller_help = command['help']
            controller_parser = subparsers.add_parser(command_name,
                                                      help=controller_help)
            controller_subparsers = controller_parser.add_subparsers()
            for controller_sub_command_name, controller_sub_command in \
                    command['sub_commands'].iteritems():
                register_command(controller_subparsers,
                                 controller_sub_command_name,
                                 controller_sub_command)
        else:

            # Add direct commands. Such as 'cfy status', 'cfy ssh' ...
            register_command(subparsers, command_name, command)

    return parser
Ejemplo n.º 5
0
def get_all_commands():

    all_commands = []
    from cloudify_cli.config.parser_config import parser_config
    parser_conf = parser_config()
    for command_name, command in parser_conf['commands'].iteritems():
        if 'sub_commands' in command:
            for sub_command_name in command['sub_commands'].keys():
                command_path = '{0} {1}'.format(command_name, sub_command_name)
                all_commands.append(command_path)
        else:
            all_commands.append(command_name)
    return all_commands
def get_all_commands():

    all_commands = []
    from cloudify_cli.config.parser_config import parser_config
    parser_conf = parser_config()
    for command_name, command in parser_conf['commands'].iteritems():
        if 'sub_commands' in command:
            for sub_command_name in command['sub_commands'].keys():
                command_path = '{0} {1}'.format(command_name, sub_command_name)
                all_commands.append(command_path)
        else:
            all_commands.append(command_name)
    return all_commands
def get_combinations(command_path):

    def traverse(dictionary, key):
        if 'sub_commands' in dictionary:
            return dictionary['sub_commands'][key]
        return dictionary[key]

    def type_of(arg):
        if 'action' in arg and arg['action'] == 'store_true':
            return bool
        if 'type' in arg:
            if isinstance(arg['type'], argparse.FileType):
                return file
            if arg['type'] == json.loads:
                return dict
        if 'type' not in arg:
            return str
        return arg['type']

    from cloudify_cli.config.parser_config import parser_config
    parser_conf = parser_config()
    reduced = reduce(traverse, command_path.split(), parser_conf['commands'])
    if 'arguments' not in reduced:
        return []

    required_args = set()
    optional_args = set()
    arguments = reduced['arguments']
    for argument_name, argument in arguments.iteritems():
        possible_arguments = argument_name.split(',')
        type_of_argument = type_of(argument)

        def add_value(arg_name):
            return '{0} {1}'.format(arg_name, ARG_VALUES[type_of_argument])

        if 'required' in argument and argument['required']:
            required_args.update(map(add_value, possible_arguments))
        else:
            optional_args.update(map(add_value, possible_arguments))

    all_commands = []
    for i in range(0, len(optional_args) + 1):
        combs = set(combinations(optional_args, i))
        for combination in combs:
            command = '{0} {1} {2}'.format(
                command_path,
                ' '.join(required_args),
                ' '.join(combination))
            all_commands.append(command)
    return all_commands
Ejemplo n.º 8
0
def get_combinations(command_path):
    def traverse(dictionary, key):
        if 'sub_commands' in dictionary:
            return dictionary['sub_commands'][key]
        return dictionary[key]

    def type_of(arg):
        if 'action' in arg and arg['action'] == 'store_true':
            return bool
        if 'type' in arg:
            if isinstance(arg['type'], argparse.FileType):
                return file
            if arg['type'] == json.loads:
                return dict
        if 'type' not in arg:
            return str
        return arg['type']

    from cloudify_cli.config.parser_config import parser_config
    parser_conf = parser_config()
    reduced = reduce(traverse, command_path.split(), parser_conf['commands'])
    if 'arguments' not in reduced:
        return []

    required_args = set()
    optional_args = set()
    arguments = reduced['arguments']
    for argument_name, argument in arguments.iteritems():
        possible_arguments = argument_name.split(',')
        type_of_argument = type_of(argument)

        def add_value(arg_name):
            return '{0} {1}'.format(arg_name, ARG_VALUES[type_of_argument])

        if 'required' in argument and argument['required']:
            required_args.update(map(add_value, possible_arguments))
        else:
            optional_args.update(map(add_value, possible_arguments))

    all_commands = []
    for i in range(0, len(optional_args) + 1):
        combs = set(combinations(optional_args, i))
        for combination in combs:
            command = '{0} {1} {2}'.format(command_path,
                                           ' '.join(required_args),
                                           ' '.join(combination))
            all_commands.append(command)
    return all_commands