mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
run_sub_commands() was the only way to access subcommands up to now, Cmds.run() adds another interface, an object as a place to add customizations affecting all commands, e.g. global command line options. Signed-off-by: Jan Lindemann <jan@janware.com>
26 lines
517 B
Python
26 lines
517 B
Python
from abc import ABCMeta, abstractmethod
|
|
|
|
import argparse
|
|
import Object
|
|
|
|
class Cmd(Object.Object): # export
|
|
|
|
__metaclass__=ABCMeta
|
|
|
|
@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
|
|
|