archivebox_config.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. __package__ = 'archivebox.cli'
  3. __command__ = 'archivebox config'
  4. import sys
  5. import argparse
  6. from typing import Optional, List, IO
  7. from ..main import config, docstring
  8. from ..config import OUTPUT_DIR
  9. from .logging import SmartFormatter, accept_stdin
  10. @docstring(config.__doc__)
  11. def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
  12. parser = argparse.ArgumentParser(
  13. prog=__command__,
  14. description=config.__doc__,
  15. add_help=True,
  16. formatter_class=SmartFormatter,
  17. )
  18. group = parser.add_mutually_exclusive_group()
  19. group.add_argument(
  20. '--get', #'-g',
  21. action='store_true',
  22. help="Get the value for the given config KEYs",
  23. )
  24. group.add_argument(
  25. '--set', #'-s',
  26. action='store_true',
  27. help="Set the given KEY=VALUE config values",
  28. )
  29. group.add_argument(
  30. '--reset', #'-s',
  31. action='store_true',
  32. help="Reset the given KEY config values to their defaults",
  33. )
  34. parser.add_argument(
  35. 'config_options',
  36. nargs='*',
  37. type=str,
  38. help='KEY or KEY=VALUE formatted config values to get or set',
  39. )
  40. command = parser.parse_args(args or ())
  41. config_options_str = accept_stdin(stdin)
  42. config(
  43. config_options_str=config_options_str,
  44. config_options=command.config_options,
  45. get=command.get,
  46. set=command.set,
  47. reset=command.reset,
  48. out_dir=pwd or OUTPUT_DIR,
  49. )
  50. if __name__ == '__main__':
  51. main(args=sys.argv[1:], stdin=sys.stdin)