2019-04-25 23:03:38 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
__package__ = 'archivebox.cli'
|
|
|
|
__command__ = 'archivebox config'
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
|
2019-04-27 21:26:24 +00:00
|
|
|
from typing import Optional, List, IO
|
2019-04-25 23:03:38 +00:00
|
|
|
|
2020-07-24 17:25:25 +00:00
|
|
|
from ..main import config
|
|
|
|
from ..util import docstring
|
2019-04-27 21:26:24 +00:00
|
|
|
from ..config import OUTPUT_DIR
|
2020-07-22 16:02:13 +00:00
|
|
|
from ..logging_util import SmartFormatter, accept_stdin
|
2019-04-25 23:03:38 +00:00
|
|
|
|
|
|
|
|
2019-05-01 03:10:48 +00:00
|
|
|
@docstring(config.__doc__)
|
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-25 23:03:38 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
prog=__command__,
|
2019-05-01 03:10:48 +00:00
|
|
|
description=config.__doc__,
|
2019-04-25 23:03:38 +00:00
|
|
|
add_help=True,
|
|
|
|
formatter_class=SmartFormatter,
|
|
|
|
)
|
|
|
|
group = parser.add_mutually_exclusive_group()
|
|
|
|
group.add_argument(
|
|
|
|
'--get', #'-g',
|
|
|
|
action='store_true',
|
|
|
|
help="Get the value for the given config KEYs",
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
'--set', #'-s',
|
|
|
|
action='store_true',
|
|
|
|
help="Set the given KEY=VALUE config values",
|
|
|
|
)
|
2019-04-26 18:43:23 +00:00
|
|
|
group.add_argument(
|
|
|
|
'--reset', #'-s',
|
|
|
|
action='store_true',
|
|
|
|
help="Reset the given KEY config values to their defaults",
|
|
|
|
)
|
2019-04-25 23:03:38 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'config_options',
|
|
|
|
nargs='*',
|
|
|
|
type=str,
|
|
|
|
help='KEY or KEY=VALUE formatted config values to get or set',
|
|
|
|
)
|
2019-04-27 21:26:24 +00:00
|
|
|
command = parser.parse_args(args or ())
|
2021-02-16 06:20:47 +00:00
|
|
|
|
|
|
|
config_options_str = ''
|
|
|
|
if not command.config_options:
|
|
|
|
config_options_str = accept_stdin(stdin)
|
2019-04-27 21:26:24 +00:00
|
|
|
|
|
|
|
config(
|
|
|
|
config_options_str=config_options_str,
|
|
|
|
config_options=command.config_options,
|
|
|
|
get=command.get,
|
|
|
|
set=command.set,
|
|
|
|
reset=command.reset,
|
|
|
|
out_dir=pwd or OUTPUT_DIR,
|
2019-04-26 18:43:13 +00:00
|
|
|
)
|
|
|
|
|
2019-04-27 21:26:24 +00:00
|
|
|
|
2019-04-25 23:03:38 +00:00
|
|
|
if __name__ == '__main__':
|
2019-04-27 21:26:24 +00:00
|
|
|
main(args=sys.argv[1:], stdin=sys.stdin)
|