(args: Optional[List[str]]=NotProvided, stdin: Optional[IO]=NotProvided, pwd: Optional[str]=None)
| 87 | |
| 88 | |
| 89 | def main(args: Optional[List[str]]=NotProvided, stdin: Optional[IO]=NotProvided, pwd: Optional[str]=None) -> None: |
| 90 | args = sys.argv[1:] if args is NotProvided else args |
| 91 | stdin = sys.stdin if stdin is NotProvided else stdin |
| 92 | |
| 93 | subcommands = list_subcommands() |
| 94 | parser = argparse.ArgumentParser( |
| 95 | prog=__command__, |
| 96 | description='ArchiveBox: The self-hosted internet archive', |
| 97 | add_help=False, |
| 98 | ) |
| 99 | group = parser.add_mutually_exclusive_group() |
| 100 | group.add_argument( |
| 101 | '--help', '-h', |
| 102 | action='store_true', |
| 103 | help=subcommands['help'], |
| 104 | ) |
| 105 | group.add_argument( |
| 106 | '--version', |
| 107 | action='store_true', |
| 108 | help=subcommands['version'], |
| 109 | ) |
| 110 | group.add_argument( |
| 111 | "subcommand", |
| 112 | type=str, |
| 113 | help= "The name of the subcommand to run", |
| 114 | nargs='?', |
| 115 | choices=subcommands.keys(), |
| 116 | default=None, |
| 117 | ) |
| 118 | parser.add_argument( |
| 119 | "subcommand_args", |
| 120 | help="Arguments for the subcommand", |
| 121 | nargs=argparse.REMAINDER, |
| 122 | ) |
| 123 | command = parser.parse_args(args or ()) |
| 124 | |
| 125 | if command.version: |
| 126 | command.subcommand = 'version' |
| 127 | elif command.help or command.subcommand is None: |
| 128 | command.subcommand = 'help' |
| 129 | |
| 130 | if command.subcommand not in ('help', 'version', 'status'): |
| 131 | from ..logging_util import log_cli_command |
| 132 | |
| 133 | log_cli_command( |
| 134 | subcommand=command.subcommand, |
| 135 | subcommand_args=command.subcommand_args, |
| 136 | stdin=stdin, |
| 137 | pwd=pwd or OUTPUT_DIR |
| 138 | ) |
| 139 | |
| 140 | run_subcommand( |
| 141 | subcommand=command.subcommand, |
| 142 | subcommand_args=command.subcommand_args, |
| 143 | stdin=stdin, |
| 144 | pwd=pwd or OUTPUT_DIR, |
| 145 | ) |
| 146 |
no test coverage detected