2019-04-03 04:27:37 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# archivebox [command]
|
|
|
|
|
|
|
|
__package__ = 'archivebox.cli'
|
|
|
|
__command__ = 'archivebox'
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
|
2019-04-27 21:26:24 +00:00
|
|
|
from typing import Optional, List, IO
|
2019-04-03 04:27:37 +00:00
|
|
|
|
2019-04-27 21:26:24 +00:00
|
|
|
from . import list_subcommands, run_subcommand
|
|
|
|
from ..config import OUTPUT_DIR
|
2019-04-03 04:27:37 +00:00
|
|
|
|
|
|
|
|
2019-04-27 21:26:24 +00:00
|
|
|
def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
|
2019-04-03 04:27:37 +00:00
|
|
|
subcommands = list_subcommands()
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
prog=__command__,
|
2019-05-01 03:10:48 +00:00
|
|
|
description='ArchiveBox: The self-hosted internet archive',
|
2019-04-03 04:27:37 +00:00
|
|
|
add_help=False,
|
|
|
|
)
|
|
|
|
group = parser.add_mutually_exclusive_group()
|
|
|
|
group.add_argument(
|
|
|
|
'--help', '-h',
|
|
|
|
action='store_true',
|
|
|
|
help=subcommands['help'],
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
'--version',
|
|
|
|
action='store_true',
|
|
|
|
help=subcommands['version'],
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
"subcommand",
|
|
|
|
type=str,
|
|
|
|
help= "The name of the subcommand to run",
|
|
|
|
nargs='?',
|
|
|
|
choices=subcommands.keys(),
|
|
|
|
default=None,
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2019-04-27 21:26:24 +00:00
|
|
|
"subcommand_args",
|
2019-04-03 04:27:37 +00:00
|
|
|
help="Arguments for the subcommand",
|
|
|
|
nargs=argparse.REMAINDER,
|
|
|
|
)
|
2019-04-27 21:26:24 +00:00
|
|
|
command = parser.parse_args(args or ())
|
2019-04-03 04:27:37 +00:00
|
|
|
|
2019-04-27 21:26:24 +00:00
|
|
|
if command.help or command.subcommand is None:
|
2019-04-03 04:27:37 +00:00
|
|
|
command.subcommand = 'help'
|
|
|
|
if command.version:
|
|
|
|
command.subcommand = 'version'
|
|
|
|
|
2019-04-27 21:26:24 +00:00
|
|
|
run_subcommand(
|
|
|
|
subcommand=command.subcommand,
|
|
|
|
subcommand_args=command.subcommand_args,
|
|
|
|
stdin=stdin,
|
|
|
|
pwd=pwd or OUTPUT_DIR,
|
|
|
|
)
|
2019-04-03 05:54:15 +00:00
|
|
|
|
2019-04-03 04:27:37 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-04-27 21:26:24 +00:00
|
|
|
main(args=sys.argv[1:], stdin=sys.stdin)
|