A CLI framework based on asyncio.
This is still in active development. Things will change. For now, the basic framework is operational. If you are interested in helping out, or would like to see any particular features added, let me know.
The simplest usage is to just pass in an
import asynccli async def mycli(): print("Hello, world.") if __name__ == '__main__': app = asynccli.App(mycli) app.run()
It can also be instantiated as a class, as long it has a
import asynccli class DivisionCalculator(asynccli.CLI): numerator = asynccli.Integer(help_text='This is the numerator.') denominator = asynccli.Integer() async def call(self): print(self.first_num / self.second_num) if __name__ == '__main__': app = asynccli.App(DivisionCalculator) app.run()
DivisionCalculator example above, you would call your script like this:
$ /path/to/script.py 2 3 0.6666666666666666
What if you want to have a tiered CLI with a hierarchy of commands? First, create your command by subclassing
CLI as above. Then, wrap the whole thing inside of the
TieredCLI class, and pass that to the
class Calculator(asynccli.TieredCLI): d = DivisionCalculator if __name__ == '__main__': app = asynccli.App(Calculator) app.run()
Now, to invoke the script, you have an extra argument to call:
$ /path/to/script.py d 2 3 0.6666666666666666
pip install asynccli
Currently it requires Python 3.5 to make use of
await. It uses
argparse under the hood, and therefore has no dependencies outside of the standard library.
- Integration of additional
- Better support for help documentation
You can invoke the test scripts a few different ways:
$ py.test $ python setup.py test $ python -m py.test
And, in order to generate the test coverage:
$ coverage run -m py.test
asynccli was written by Adam Hopkins.