Simple subcommand CLIs with argparse
multicommand
Simple subcommand CLIs with argparse.
multicommand
uses only the standard library and is ~100 lines of code (modulo comments and whitespace)
Installation
pip install multicommand
Overview
Multicommand enables you to easily write CLIs with deeply nested commands using vanilla argparse. You provide it with a package, it searches that package for parsers (ArgumentParser
objects), and connects, names, and converts those parsers into subcommands based on the package structure.
Package -> CLI
commands/unary/negate.py mycli unary negate ...
commands/binary/add.py mycli binary add ...
commands/binary/divide.py -> mycli binary divide ...
commands/binary/multiply.py mycli binary multiply ...
commands/binary/subtract.py mycli binary subtract ...
All it needs is for each module to define a module-level parser
variable which points to an instance of argparse.ArgumentParser
.
Motivation
I like