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.

Source Distribution

asynccmd-0.2.1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distributions

asynccmd-0.2.1-py3.7.egg (7.4 kB view hashes)

Uploaded Source

asynccmd-0.2.1-py3.6.egg (7.4 kB view hashes)

Uploaded Source

asynccmd-0.2.1-py3.5.egg (7.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page