from __future__ import print_function import sys import os from ruamel.std.argparse import ProgramBase, option, sub_parser, version, \ SmartFormatter class TestCmd(ProgramBase): def __init__(self): super(TestCmd, self).__init__( formatter_class=SmartFormatter ) # you can put these on __init__, but subclassing TestCmd # will cause that to break @option('--quiet', '-q', help='suppress verbosity', action='store_true', global_option=True) @version('version: 1.2.3') def _pb_init(self): # special name for which attribs are included in help pass def run(self): if self._args.func: return self._args.func() def parse_args(self, *args): self._parse_args(*args) @sub_parser(help='specific help for readit') @option('--name', default='abc') def readit(self): print('calling readit') @sub_parser('writeit', help='help for writeit') @option('--target') def other_name(self): print('calling writeit') n = TestCmd() n.parse_args(['--help']) n.run()