2020-01-01 09:59:47 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-01-03 10:02:39 +00:00
|
|
|
import argparse
|
|
|
|
import importlib
|
2020-01-01 09:59:47 +00:00
|
|
|
|
2020-01-03 10:02:39 +00:00
|
|
|
arg_parser = argparse.ArgumentParser('cli', add_help=False)
|
|
|
|
subparser = arg_parser.add_subparsers(dest='subcommand')
|
2020-01-01 09:59:47 +00:00
|
|
|
|
2020-01-03 10:02:39 +00:00
|
|
|
for component in ['user', 'host', 'image', 'network', 'vm']:
|
|
|
|
module = importlib.import_module('uncloud.cli.{}'.format(component))
|
|
|
|
parser = getattr(module, 'arg_parser')
|
|
|
|
subparser.add_parser(name=parser.prog, parents=[parser])
|
2020-01-01 09:59:47 +00:00
|
|
|
|
|
|
|
|
2020-01-10 11:39:40 +00:00
|
|
|
def main(arguments):
|
|
|
|
if not arguments['subcommand']:
|
2020-01-03 10:02:39 +00:00
|
|
|
arg_parser.print_help()
|
|
|
|
else:
|
2020-01-10 11:39:40 +00:00
|
|
|
name = arguments.pop('subcommand')
|
|
|
|
arguments.pop('debug')
|
2020-01-03 10:02:39 +00:00
|
|
|
mod = importlib.import_module('uncloud.cli.{}'.format(name))
|
|
|
|
_main = getattr(mod, 'main')
|
2020-01-10 11:39:40 +00:00
|
|
|
_main(**arguments)
|