find and import all valid archivebox_ .py files in CLI_DIR
()
| 34 | |
| 35 | |
| 36 | def list_subcommands() -> Dict[str, str]: |
| 37 | """find and import all valid archivebox_<subcommand>.py files in CLI_DIR""" |
| 38 | |
| 39 | COMMANDS = [] |
| 40 | for filename in os.listdir(CLI_DIR): |
| 41 | if is_cli_module(filename): |
| 42 | subcommand = filename.replace('archivebox_', '').replace('.py', '') |
| 43 | module = import_module('.archivebox_{}'.format(subcommand), __package__) |
| 44 | assert is_valid_cli_module(module, subcommand) |
| 45 | COMMANDS.append((subcommand, module.main.__doc__)) |
| 46 | globals()[subcommand] = module.main |
| 47 | |
| 48 | display_order = lambda cmd: ( |
| 49 | display_first.index(cmd[0]) |
| 50 | if cmd[0] in display_first else |
| 51 | 100 + len(cmd[0]) |
| 52 | ) |
| 53 | |
| 54 | return dict(sorted(COMMANDS, key=display_order)) |
| 55 | |
| 56 | |
| 57 | def run_subcommand(subcommand: str, |
no outgoing calls
no test coverage detected