123456789101112131415161718192021222324 |
- import argparse
-
- from .errors import ArgumentParserError
-
- class CommandParser(argparse.ArgumentParser):
- """ ArgumentParser raising exception instead of exiting and printing help
- """
-
- def error(self, message):
- """ Raise an exception instead of printing to stderr and exiting """
- raise ArgumentParserError(message)
-
- def exit(self, *args):
- """ Do not allow a parser to exit the programm """
- pass
-
- def print_help(self, *args):
- """ If print_help() is called raise an exception """
- raise ArgumentParserError(self.format_usage())
-
- def add_subparsers(self, *args, **kwargs):
- """ Create subparsers indicated the good parser class """
- return super().add_subparsers(*args, **kwargs,
- parser_class=self.__class__)
|