This is the main function for the Mesos CLI.
(argv)
| 79 | |
| 80 | |
| 81 | def main(argv): |
| 82 | """ |
| 83 | This is the main function for the Mesos CLI. |
| 84 | """ |
| 85 | |
| 86 | # Load the CLI config. |
| 87 | config = cli.config.Config(settings) |
| 88 | |
| 89 | plugins = cli.util.import_modules( |
| 90 | cli.util.join_plugin_paths(settings, config), |
| 91 | "plugins") |
| 92 | |
| 93 | cmds = { |
| 94 | cli.util.get_module(plugins, plugin).PLUGIN_NAME: |
| 95 | cli.util.get_module(plugins, plugin).SHORT_HELP |
| 96 | for plugin in list(plugins.keys()) |
| 97 | } |
| 98 | |
| 99 | # Parse all incoming arguments using docopt. |
| 100 | command_strings = "" |
| 101 | if cmds != {}: |
| 102 | command_strings = cli.util.format_commands_help(cmds) |
| 103 | usage = USAGE.format(commands=command_strings) |
| 104 | |
| 105 | arguments = docopt(usage, argv=argv, version=VERSION, options_first=True) |
| 106 | |
| 107 | cmd = arguments["<command>"] |
| 108 | argv = arguments["<args>"] |
| 109 | |
| 110 | # Use the meta-command `__autocomplete__` to perform |
| 111 | # autocompletion on the remaining arguments. |
| 112 | if cmd == "__autocomplete__": |
| 113 | option = "default" |
| 114 | comp_words = [] |
| 115 | |
| 116 | # If there is an error performing the autocomplete, treat it |
| 117 | # as if we were just unable to complete any words. This avoids |
| 118 | # passing the erroring stack trace back as the list of words |
| 119 | # to complete on. |
| 120 | try: |
| 121 | option, comp_words = autocomplete(cmds, plugins, config, argv) |
| 122 | except Exception: |
| 123 | pass |
| 124 | |
| 125 | print(option) |
| 126 | print(" ".join(comp_words)) |
| 127 | return 0 |
| 128 | |
| 129 | # Use the meta-command "help" to print help information for the |
| 130 | # supplied command and its subcommands. |
| 131 | if cmd == "help": |
| 132 | if argv and argv[0] in cmds: |
| 133 | plugin = cli.util.get_module(plugins, argv[0]) |
| 134 | plugin_class = getattr(plugin, plugin.PLUGIN_CLASS) |
| 135 | return plugin_class(settings, config).main(argv[1:] + ["--help"]) |
| 136 | |
| 137 | return main(["--help"]) |
| 138 |