Fork me on GitHub

Cmd3

Python has provided for a long time a very useful framework for creating simple command line shells via Cmd. Other projects have made use of them and extended it in various ways such as Cmd2. Although these tools are great, we found several features missing from them to make them more usable for our projects. Two of the main features we needed were a mechanism to

  • add plugins via a plugin directory and
  • a better automatic option parsing

while at the same time automatically generating the help messages from them. While our developers used optparse and argparse for this we found that the resulting code not necessarily lead to a proper documentation based on the complexity involved with dealing with the right syntactic layout using the parsers. Instead we decided to use docopt for our parsing that makes it possible to create the documentation in a single easy to write docstring and accessing them from our methods to create a data structure that simplifies the creation of writing programs using the information passed to the functions. Naturally if you do not want to use docopt, you can still use other argument parsers. In addition we also introduced a scope that allows us to save some typing while all commands executed in a scope will be preceded by the scope name. We also have introduced simple variable substitution based on variable names that follow the syntax $variable.

Here is a list of features that we found important:

  • dynamic class creation
  • plugins loadable via a plugin directory
  • easy installation with setup.py
  • deployment via pip and pypi
  • variable substitution
  • scripts loadable from a script directory
  • adding new commands through importable modules and plugins
  • being able to manage new commands in independent packages

The Source code is located at:

Indices and tables

Index Module Index Search Page

Modules