PyDocs

Nav

Command-line interface libraries

Cmd

cmd

class (source)
  • Cmd(completekey='tab', stdin=None, stdout=None)
A simple framework for writing line-oriented command interpreters.

These are often useful for test harnesses, administrative tools, and
prototypes that will later be wrapped in a more sophisticated interface.

A Cmd instance or subclass instance is a line-oriented interpreter
framework.  There is no good reason to instantiate Cmd itself; rather,
it's useful as a superclass of an interpreter class you define yourself
in order to inherit Cmd's methods and encapsulate action methods.
Changed in 3.13
  • 3.13: completekey='tab' is replaced by '^I' for editline.
Members of Cmd

c

cmdloop
Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument.
cmdqueue
A list of queued input lines.
columnize
Display a list of strings as a compact set of columns.
completedefault
Method called to complete an input line when no command-specific complete_*() method is available.

d

default
Called on an input line when the command prefix is not recognized.
do_help
List available commands with "help" or detailed help with "help cmd".
doc_header
The header to issue if the help output has a section for documented commands.

e

emptyline
Called when an empty line is entered in response to the prompt.

i

identchars
The string of characters accepted for the command prefix.
intro
A string to issue as an intro or banner.

l

lastcmd
The last nonempty command prefix seen.

m

misc_header
The header to issue if the help output has a section for miscellaneous help topics (that is, there are help_*() methods without corresponding do_*() methods).

o

onecmd
Interpret the argument as though it had been typed in response to the prompt.

p

postcmd
Hook method executed just after a command dispatch is finished.
postloop
Hook method executed once when the cmdloop() method is about to return.
precmd
Hook method executed just before the command line is interpreted, but after the input prompt is generated and issued.
preloop
Hook method executed once when the cmdloop() method is called.
prompt
The prompt issued to solicit input.

r

ruler
The character used to draw separator lines under the help-message headers.

u

undoc_header
The header to issue if the help output has a section for undocumented commands (that is, there are do_*() methods without corresponding help_*() methods).
use_rawinput
A flag, defaulting to true.
0 Examples
No examples for cmd/Cmd.
See Also
No see-alsos for cmd/Cmd
0 Notes
No notes for Cmd