argparse
parsers
Combining This is a proof of concept for a command line interface (CLI) that is subclassable.
TO use, create an instance of the class (or subclass) and call it's main
method.
The only tricky part is that subclasses need to pass add_parser_help=False
when calling the BaseCLI's __init__
method.
base.py
by itself
Using > ./base.py -h
usage: base.py [-h] [--token TOKEN]
Base class CLI.
optional arguments:
-h, --help show this help message and exit
--token TOKEN Token from the content server
Example usage
> ./base.py --token THISISATOKEN
In BaseCLI's main method. args= Namespace(token='THISISATOKEN')
In BaseCLI's importchannel command.
args: Namespace(token='THISISATOKEN')
subclass.py
Using > ./subclass.py -h
usage: subclass.py [-h] [--token TOKEN] [--step STEP]
Subclass CLI demo
optional arguments:
-h, --help show this help message and exit
--token TOKEN Token from the content server
--step STEP An argument specific to the SubclassCLI
Example usage:
> ./subclass.py --token THISISANOTERTOKEN --step 3
In SubclassCLI's main method. args= Namespace(step='3', token='THISISANOTERTOKEN')
In BaseCLI's importchannel command.
args: Namespace(step='3', token='THISISANOTERTOKEN')