A command subparser utility.
Subcomm provides a clear API for creating subcommands.
Supports Python: 3.5, 3.6, 3.7
$ pip install subcomm
Create the command parser:
parser = SubcommParser(description='Command parser.')
When declaring commands, use the @parser.command decorator:
@parser.command(help='Run the command start.') def start(file): return 0 start.parser.add_argument('file')
You can customize the subparser by accessing it as an attribute of the function: start.parser, so you can add arguments to the subcommand or any other parser behavior using the default argparse API. Arguments will be passed to the command handler by the names they would have in parser.parse_args().
You call the handlers by doing:
The value returned by the handler will be returned to the caller. If you are running a script and you want to return something consistent with the return values of the handlers, do:
If the code is in a script called run.py, then you can run it using:
python run.py command
That’s the same thing as calling the command function.
If you want a default command, so you can just call python run.py, then you can declare:
@parser.default(help='Help for the subcommand.') def start(args): pass
You can only declare one default command at a time.
Install for development and with dependencies:
$ pip install -e .[dev]
Asserting code quality
Of course we use our own API, so:
$ python dev.py quality
$ python dev.py test
This will report code coverage as well.
To run tests with tox, run:
Packaging for PyPI distribution
$ python dev.py package
The build will happen if the repository passes the quality tests and is clean: no untracked files are found. If not, you can see what’s wrong with git clean -dfx --dry-run and remove or track and commit those files.
Builds will be available at dist, in wheel and source.
Pull requests are welcome.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size subcomm-0.3.3-py3-none-any.whl (4.1 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size subcomm-0.3.3.tar.gz (4.2 kB)||File type Source||Python version None||Upload date||Hashes View|