Skip to main content

Asyncio implementation of Cmd Python lib.

Project description

asynccmd Async implementation of cmd Python lib.

Build Status codecov PyPI version

It’s very simple like original Cmd lib https://docs.python.org/3.6/library/cmd.html.

The mechanic is very similar. You have Cmd class, you can override class method and add yours own.

import asyncio
import sys
from asynccmd import Cmd

class SimpleCommander(Cmd):
    def __init__(self, mode, intro, prompt):
        super().__init__(mode=mode)
        self.intro = intro
        self.prompt = prompt
        self.loop = None

    def do_tasks(self, arg):
        """
        Fake command. Type "tasks {arg}"
        :param arg: args occurred from cmd after command
        :return:
        """
        print(asyncio.Task.all_tasks(loop=self.loop))

    def start(self, loop=None):
        self.loop = loop
        super().cmdloop(loop)
        print(super().mode)

if sys.platform == 'win32':
   loop = asyncio.ProactorEventLoop()
   mode = "Run"
else:
   loop = asyncio.get_event_loop()
   mode = "Reader"
cmd = SimpleCommander(mode=mode, intro="This is example", prompt="example> ")
cmd.start(loop)
try:
    loop.run_forever()
except KeyboardInterrupt:
    loop.stop()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for asynccmd, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size asynccmd-0.2.1-py3.5.egg (7.5 kB) File type Egg Python version 3.5 Upload date Hashes View
Filename, size asynccmd-0.2.1-py3.6.egg (7.4 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size asynccmd-0.2.1-py3.7.egg (7.4 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size asynccmd-0.2.1.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page