cmd3 Package

cmd3 Package

shell Module

This project is about developing a dynamic CMD class based on cmd.CMD. We assume the following directory structure:


We have provides examples of the classes in this document

foo and bar contain some classes that include he usual do_ methods. It also includes an activate method that is called wih the acivation module, so you can control its behavior upon startup.

To specify the plugins please use:

plugins = ["foo", "bar","activate"]

Now you can set a name for your class:

name = "CmCLI"

The rest is pretty simple:

(cmd, plugin_objects) = DynamicCmd(name, plugins)

The activate method is not called automatically as to give more flexibility during startup.

Here are the sample classes:

class bar:

    def activate_bar(self):
        print "... activate bar"

    def do_that(self, arg):
        print "THAT", arg

class foo:

    def do_this(self, arg):
        print "THIS", arg

    def activate_foo(self):
        print "... activate foo"

class activate:

    active = False

    def do_on(self, arg): = True

    def do_off(self, arg): = False

    def activate_status(self):
        print "Active:",

    def activate(self, plugins):
        d = dir(self)
        result = []
        for key in d:
            if key.startswith("activate_"):
        print result
        for key in result:
            print "> %s" % key.replace("_"," ")
            exec("self.%s()" % key)