__init__.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import argparse
  2. from reddrip.util.log import setup_logging
  3. from reddrip.util.parse import setup_parser
  4. # Import commands.
  5. from reddrip.commands.run import RunCommand
  6. from reddrip.commands.stat import StatCommand
  7. def main(args):
  8. """ Main entry point for the CLI scripts."""
  9. early_parser = argparse.ArgumentParser(
  10. # Turn off help, so that we can show all options in the real parser.
  11. add_help=False,
  12. )
  13. early_parser.add_argument(
  14. "--verbose", "-v", default=False, action="store_true",
  15. help="verbose logging"
  16. )
  17. # Bootstrap the context.
  18. (options, additional_args) = early_parser.parse_known_args(args)
  19. setup_logging(verbose=options.verbose, color=True)
  20. # Now initialize the real parser.
  21. parser = argparse.ArgumentParser(
  22. parents=[ early_parser ],
  23. description="Command line interface for Reddrip.",
  24. )
  25. commands = {
  26. "run": RunCommand,
  27. "stat": StatCommand,
  28. }
  29. setup_parser(parser, commands)
  30. # Parse the rest of the command arguments.
  31. options = parser.parse_args(args)
  32. command = options.command()
  33. command.execute(options)