Main run method. Called for all sub-commands and parameters. It sets up argument parsing, then calls the sub-command method with the same name.
(self, arguments=None)
| 206 | self.current_version = self.getMongoDVersion(False) |
| 207 | |
| 208 | def run(self, arguments=None): |
| 209 | """ |
| 210 | Main run method. |
| 211 | |
| 212 | Called for all sub-commands and parameters. It sets up argument |
| 213 | parsing, then calls the sub-command method with the same name. |
| 214 | """ |
| 215 | # set up argument parsing in run, so that subsequent calls |
| 216 | # to run can call different sub-commands |
| 217 | self.argparser = argparse.ArgumentParser() |
| 218 | self.argparser.add_argument('--version', action='version', |
| 219 | version=f'''mtools version {__version__} || Python {sys.version}''') |
| 220 | self.argparser.add_argument('--no-progressbar', action='store_true', |
| 221 | default=False, |
| 222 | help='disables progress bar') |
| 223 | |
| 224 | self.argparser.description = ('script to launch MongoDB stand-alone ' |
| 225 | 'servers, replica sets and shards.') |
| 226 | |
| 227 | # make sure init is default command even when specifying |
| 228 | # arguments directly |
| 229 | if arguments and arguments.startswith('-'): |
| 230 | arguments = 'init ' + arguments |
| 231 | |
| 232 | # default sub-command is `init` if none provided |
| 233 | elif (len(sys.argv) > 1 and sys.argv[1].startswith('-') and |
| 234 | sys.argv[1] not in ['-h', '--help', '--version']): |
| 235 | sys.argv = sys.argv[0:1] + ['init'] + sys.argv[1:] |
| 236 | |
| 237 | # create command sub-parsers |
| 238 | subparsers = self.argparser.add_subparsers(dest='command') |
| 239 | self.argparser._action_groups[0].title = 'commands' |
| 240 | self.argparser._action_groups[0].description = \ |
| 241 | ('init is the default command and can be omitted. To get help on ' |
| 242 | 'individual commands, run mlaunch <command> --help. Command line ' |
| 243 | 'arguments which are not handled by mlaunch will be passed ' |
| 244 | 'through to mongod/mongos if those options are listed in the ' |
| 245 | '--help output for the current binary. For example: ' |
| 246 | '--storageEngine, --logappend, or --config.') |
| 247 | |
| 248 | # init command |
| 249 | helptext = ('initialize a new MongoDB environment and start ' |
| 250 | 'stand-alone instances, replica sets, or sharded ' |
| 251 | 'clusters.') |
| 252 | desc = ('Initialize a new MongoDB environment and start stand-alone ' |
| 253 | 'instances, replica sets, or sharded clusters. Command line ' |
| 254 | 'arguments which are not handled by mlaunch will be passed ' |
| 255 | 'through to mongod/mongos if those options are listed in the ' |
| 256 | '--help output for the current binary. For example: ' |
| 257 | '--storageEngine, --logappend, or --config.') |
| 258 | init_parser = subparsers.add_parser('init', help=helptext, |
| 259 | description=desc) |
| 260 | |
| 261 | # either single or replica set |
| 262 | me_group = init_parser.add_mutually_exclusive_group(required=True) |
| 263 | me_group.add_argument('--single', action='store_true', |
| 264 | help=('creates a single stand-alone mongod ' |
| 265 | 'instance')) |
no outgoing calls