cmdparser.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #
  2. # Metrix++, Copyright 2009-2013, Metrix++ Project
  3. # Link: http://swi.sourceforge.net
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. # Metrix++ is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Metrix++ is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import optparse
  20. class MultiOptionParser(optparse.OptionParser):
  21. class MultipleOption(optparse.Option):
  22. ACTIONS = optparse.Option.ACTIONS + ("multiopt",)
  23. STORE_ACTIONS = optparse.Option.STORE_ACTIONS + ("multiopt",)
  24. TYPED_ACTIONS = optparse.Option.TYPED_ACTIONS + ("multiopt",)
  25. ALWAYS_TYPED_ACTIONS = optparse.Option.ALWAYS_TYPED_ACTIONS + ("multiopt",)
  26. def take_action(self, action, dest, opt, value, values, parser):
  27. if action == "multiopt":
  28. values.ensure_value(dest, []).append(value)
  29. else:
  30. optparse.Option.take_action(self, action, dest, opt, value, values, parser)
  31. def __init__(self, *args, **kwargs):
  32. optparse.OptionParser.__init__(self, *args, option_class=self.MultipleOption, **kwargs)