You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. from argparse import ArgumentParser
  2. class GooeyParser(object):
  3. def __init__(self, **kwargs):
  4. self.__dict__['parser'] = ArgumentParser(**kwargs)
  5. self.widgets = {}
  6. @property
  7. def _mutually_exclusive_groups(self):
  8. return self.parser._mutually_exclusive_groups
  9. @property
  10. def _actions(self):
  11. return self.parser._actions
  12. @property
  13. def description(self):
  14. return self.parser.description
  15. def add_argument(self, *args, **kwargs):
  16. widget = kwargs.pop('widget', None)
  17. self.parser.add_argument(*args, **kwargs)
  18. self.widgets[self.parser._actions[-1].dest] = widget
  19. def add_mutually_exclusive_group(self, **kwargs):
  20. return self.parser.add_mutually_exclusive_group(**kwargs)
  21. def add_argument_group(self, *args, **kwargs):
  22. return self.parser.add_argument_group(*args, **kwargs)
  23. def parse_args(self, args=None, namespace=None):
  24. return self.parser.parse_args(args, namespace)
  25. def __getattr__(self, item):
  26. return getattr(self.parser, item)
  27. def __setattr__(self, key, value):
  28. return setattr(self.parser, key, value)