jw-python/tools/python/jwutils/Cmd.py

25 lines
552 B
Python
Raw Normal View History

import abc
import argparse
# compatible with Python 2 *and* 3
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
class Cmd(ABC): # export
@abc.abstractmethod
def run(self, args):
pass
def __init__(self, name, help):
self.name = name
self.help = help
def _run(self, args):
pass
def add_parser(self, parsers):
r = parsers.add_parser(self.name, help=self.help,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
r.set_defaults(func=self.run)
return r