aiocmd

raw JSON →
0.1.5 verified Fri May 01 auth: no python

Coroutine-based CLI generator using prompt_toolkit. Version 0.1.5 (latest) with no new releases since 2020; project appears unmaintained.

pip install aiocmd
error AttributeError: 'MyCli' object has no attribute 'cmd_help'
cause run_cmd expects methods with 'cmd_' prefix; method missing or incorrectly named.
fix
Add an async method with name starting with 'cmd_', e.g., 'async def cmd_help(self):'
error TypeError: run_cmd() missing 1 required positional argument: 'cli_cmd'
cause run_cmd called without arguments or with wrong number of arguments.
fix
Call 'run_cmd(cli_instance)' where cli_instance is an instance of a CliCmd subclass.
gotcha Methods must be async and prefixed with 'cmd_'. Forgetting 'async' or wrong prefix causes method to be ignored silently.
fix Ensure all command methods are defined as 'async def cmd_<command>(self, ...):'
gotcha run_cmd expects an instance of CliCmd, not the class itself. Passing the class will result in AttributeError.
fix Use 'run_cmd(MyCli())' not 'run_cmd(MyCli)'

Define a class inheriting from CliCmd with async methods prefixed with 'cmd_' and run with run_cmd.

import asyncio
from aiocmd import CliCmd, run_cmd

class MyCli(CliCmd):
    async def cmd_hello(self):
        """Say hello"""
        print("Hello, world!")

if __name__ == '__main__':
    asyncio.run(run_cmd(MyCli()))