archivebox_version.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. __package__ = 'archivebox.cli'
  3. __command__ = 'archivebox version'
  4. import sys
  5. import argparse
  6. from pathlib import Path
  7. from typing import Optional, List, IO
  8. # from archivebox.misc.util import docstring
  9. from archivebox.config import DATA_DIR, VERSION
  10. from ..logging_util import SmartFormatter, reject_stdin
  11. # @docstring(version.__doc__)
  12. def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
  13. """Print the ArchiveBox version and dependency information"""
  14. parser = argparse.ArgumentParser(
  15. prog=__command__,
  16. description="Print the ArchiveBox version and dependency information", # version.__doc__,
  17. add_help=True,
  18. formatter_class=SmartFormatter,
  19. )
  20. parser.add_argument(
  21. '--quiet', '-q',
  22. action='store_true',
  23. help='Only print ArchiveBox version number and nothing else.',
  24. )
  25. command = parser.parse_args(args or ())
  26. reject_stdin(__command__, stdin)
  27. # for speed reasons, check if quiet flag was set and just return simple version immediately if so
  28. if command.quiet:
  29. print(VERSION)
  30. return
  31. # otherwise do big expensive import to get the full version
  32. from ..main import version
  33. version(
  34. quiet=command.quiet,
  35. out_dir=Path(pwd) if pwd else DATA_DIR,
  36. )
  37. if __name__ == '__main__':
  38. main(args=sys.argv[1:], stdin=sys.stdin)