Exemplo n.º 1
0
    def main(self, argv):
        """
        Main method takes argument from top level mesos and parses them
        to call the appropriate method.
        """
        command_strings = mesos.util.format_commands_help(self.COMMANDS)

        usage = self.USAGE.format(
            plugin=self.PLUGIN_NAME,
            short_help=self.SHORT_HELP,
            commands=command_strings)

        arguments = docopt(
            usage,
            argv=argv,
            version=self.VERSION,
            program="mesos " + self.PLUGIN_NAME,
            options_first=True)

        cmd = arguments["<command>"]
        argv = arguments["<args>"]

        if cmd in self.COMMANDS.keys():
            if "external" not in self.COMMANDS[cmd]:
                argument_format, short_help, long_help, flag_format = \
                    mesos.util.format_subcommands_help(self.COMMANDS[cmd])

                usage = SUBCOMMAND_USAGE.format(
                    plugin=self.PLUGIN_NAME,
                    command=cmd,
                    arguments=argument_format,
                    flags=flag_format,
                    short_help=short_help,
                    long_help=long_help)

                arguments = docopt(
                    usage,
                    argv=argv,
                    program="mesos " + self.PLUGIN_NAME + " " + cmd,
                    version=self.VERSION,
                    options_first=True)

            self.__setup__(cmd, argv)
            getattr(self, cmd.replace("-", "_"))(arguments)
        else:
            self.main(["--help"])
Exemplo n.º 2
0
    def main(self, argv):
        command_strings = mesos.util.format_commands_help(self.COMMANDS)

        usage = self.USAGE.format(plugin=self.PLUGIN_NAME,
                                  short_help=self.SHORT_HELP,
                                  commands=command_strings)

        arguments = docopt(usage,
                           argv=argv,
                           version=self.VERSION,
                           program="mesos " + self.PLUGIN_NAME,
                           options_first=True)

        cmd = arguments["<command>"]
        argv = arguments["<args>"]

        if cmd in self.COMMANDS.keys():
            if "external" not in self.COMMANDS[cmd]:
                argument_format, short_help, long_help, flag_format = \
                    mesos.util.format_subcommands_help(self.COMMANDS[cmd])

                usage = SUBCOMMAND_USAGE.format(plugin=self.PLUGIN_NAME,
                                                command=cmd,
                                                arguments=argument_format,
                                                flags=flag_format,
                                                short_help=short_help,
                                                long_help=long_help)

                arguments = docopt(usage,
                                   argv=argv,
                                   program="mesos " + self.PLUGIN_NAME + " " +
                                   cmd,
                                   version=self.VERSION,
                                   options_first=True)

            self.__setup__(cmd, argv)
            getattr(self, cmd.replace("-", "_"))(arguments)
        else:
            self.main(["--help"])
Exemplo n.º 3
0
def main(argv):
    """
    This is the main function for the Mesos CLI.
    """

    # Initialize the various plugins.
    plugins = mesos.util.import_modules(config.PLUGINS, "plugins")

    cmds = {
        mesos.util.get_module(plugins, plugin).PLUGIN_NAME:
        mesos.util.get_module(plugins, plugin).SHORT_HELP
        for plugin in plugins.keys()
    }

    # Parse all incoming arguments using docopt.
    command_strings = ""
    if cmds != {}:
        command_strings = mesos.util.format_commands_help(cmds)
    usage = USAGE.format(commands=command_strings)

    arguments = docopt(usage, argv=argv, version=VERSION, options_first=True)

    cmd = arguments["<command>"]
    argv = arguments["<args>"]

    # Use the meta-command `__autocomplete__` to perform
    # autocompletion on the remaining arguments.
    if cmd == "__autocomplete__":
        current_word = argv[0]
        argv = argv[1:]

        option = "default"
        comp_words = []

        # If there is an error performing the autocomplete, treat it
        # as if we were just unable to complete any words. This avoids
        # passing the erroring stack trace back as the list of words
        # to complete on.
        try:
            option, comp_words = autocomplete(cmds, plugins, current_word, argv)
        except Exception:
            pass

        print option
        print " ".join(comp_words)

    # Use the meta-command "help" to print help information for the
    # supplied command and its subcommands.
    elif cmd == "help":
        if len(argv) > 0 and argv[0] in cmds:
            plugin = mesos.util.get_module(plugins, argv[0])
            plugin_class = getattr(plugin, plugin.PLUGIN_CLASS)
            plugin_class(config).main(argv[1:] + ["--help"])
        else:
            main(["--help"])

    # Run the command through its plugin.
    elif cmd in cmds.keys():
        plugin = mesos.util.get_module(plugins, cmd)
        plugin_class = getattr(plugin, plugin.PLUGIN_CLASS)
        plugin_class(config).main(argv)

    # Print help information if no commands match.
    else:
        main(["--help"])
Exemplo n.º 4
0
def main(argv):
    """
    This is the main function for the Mesos CLI.
    """

    # Initialize the various plugins.
    plugins = mesos.util.import_modules(config.PLUGINS, "plugins")

    cmds = {
        mesos.util.get_module(plugins, plugin).PLUGIN_NAME:
        mesos.util.get_module(plugins, plugin).SHORT_HELP
        for plugin in plugins.keys()
    }

    # Parse all incoming arguments using docopt.
    command_strings = ""
    if cmds != {}:
        command_strings = mesos.util.format_commands_help(cmds)
    usage = USAGE.format(commands=command_strings)

    arguments = docopt(usage, argv=argv, version=VERSION, options_first=True)

    cmd = arguments["<command>"]
    argv = arguments["<args>"]

    # Use the meta-command `__autocomplete__` to perform
    # autocompletion on the remaining arguments.
    if cmd == "__autocomplete__":
        current_word = argv[0]
        argv = argv[1:]

        option = "default"
        comp_words = []

        # If there is an error performing the autocomplete, treat it
        # as if we were just unable to complete any words. This avoids
        # passing the erroring stack trace back as the list of words
        # to complete on.
        try:
            option, comp_words = autocomplete(cmds, plugins, current_word,
                                              argv)
        except Exception:
            pass

        print option
        print " ".join(comp_words)

    # Use the meta-command "help" to print help information for the
    # supplied command and its subcommands.
    elif cmd == "help":
        if len(argv) > 0 and argv[0] in cmds:
            plugin = mesos.util.get_module(plugins, argv[0])
            plugin_class = getattr(plugin, plugin.PLUGIN_CLASS)
            plugin_class(config).main(argv[1:] + ["--help"])
        else:
            main(["--help"])

    # Run the command through its plugin.
    elif cmd in cmds.keys():
        plugin = mesos.util.get_module(plugins, cmd)
        plugin_class = getattr(plugin, plugin.PLUGIN_CLASS)
        plugin_class(config).main(argv)

    # Print help information if no commands match.
    else:
        main(["--help"])