<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>5.10.1 Cmd Objects</TITLE>
<META NAME="description" CONTENT="5.10.1 Cmd Objects">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="lib.css">
<LINK REL="previous" HREF="module-cmd.html">
<LINK REL="up" HREF="module-cmd.html">
<LINK REL="next" HREF="module-shlex.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-shlex.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-cmd.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-cmd.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-shlex.html">5.11 shlex  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-cmd.html">5.10 cmd  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-cmd.html">5.10 cmd  </A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION0071010000000000000000"></A>
<BR>
5.10.1 Cmd Objects
</H2>

<P>
A <tt class=class>Cmd</tt> instance has the following methods:

<P>
<dl><dt><b><a name="l2h-832"><tt class=method>cmdloop</tt></a></b> (<big>[</big><var>intro</var><big>]</big>)
<dd>
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.

<P>
The optional argument is a banner or intro string to be issued before the
first prompt (this overrides the <tt class=member>intro</tt> class member).

<P>
If the <tt class=module>readline</tt> module is loaded, input will automatically
inherit <b class=program>bash</b>-like history-list editing (e.g. <kbd>Ctrl-P</kbd>
scrolls back to the last command, <kbd>Ctrl-N</kbd> forward to the next
one, <kbd>Ctrl-F</kbd> moves the cursor to the right non-destructively,
<kbd>Ctrl-B</kbd> moves the cursor to the left non-destructively, etc.).

<P>
An end-of-file on input is passed back as the string <tt>'EOF'</tt>.

<P>
An interpreter instance will recognize a command name "<tt class=samp>foo</tt>" if
and only if it has a method <tt class=method>do_foo()</tt>.  As a special case,
a line containing only the character "<tt class=character>?</tt>" is dispatched to
the method <tt class=method>do_help()</tt>.  As another special case, a line
containing only the character "<tt class=character>!</tt>" is dispatched to the
method <tt class=method>do_shell</tt> (if such a method is defined).

<P>
All subclasses of <tt class=class>Cmd</tt> inherit a predefined <tt class=method>do_help</tt>.
This method, called with an argument <tt>bar</tt>, invokes the
corresponding method <tt class=method>help_bar()</tt>.  With no argument,
<tt class=method>do_help()</tt> lists all available help topics (that is, all
commands with corresponding <tt class=method>help_*()</tt> methods), and also lists
any undocumented commands.
</dl>

<P>
<dl><dt><b><a name="l2h-833"><tt class=method>onecmd</tt></a></b> (<var>str</var>)
<dd>
Interpret the argument as though it had been typed in in
response to the prompt.
</dl>

<P>
<dl><dt><b><a name="l2h-834"><tt class=method>emptyline</tt></a></b> ()
<dd>
Method called when an empty line is entered in response to the prompt.
If this method is not overridden, it repeats the last nonempty command
entered.  
</dl>

<P>
<dl><dt><b><a name="l2h-835"><tt class=method>default</tt></a></b> (<var>line</var>)
<dd>
Method called on an input line when the command prefix is not
recognized. If this method is not overridden, it prints an
error message and returns.
</dl>

<P>
<dl><dt><b><a name="l2h-836"><tt class=method>precmd</tt></a></b> ()
<dd>
Hook method executed just before the input prompt is issued.  This
method is a stub in <tt class=class>Cmd</tt>; it exists to be overridden by
subclasses.
</dl>

<P>
<dl><dt><b><a name="l2h-837"><tt class=method>postcmd</tt></a></b> ()
<dd>
Hook method executed just after a command dispatch is finished.  This
method is a stub in <tt class=class>Cmd</tt>; it exists to be overridden by
subclasses.
</dl>

<P>
<dl><dt><b><a name="l2h-838"><tt class=method>preloop</tt></a></b> ()
<dd>
Hook method executed once when <tt class=method>cmdloop()</tt> is called.  This
method is a stub in <tt class=class>Cmd</tt>; it exists to be overridden by
subclasses.
</dl>

<P>
<dl><dt><b><a name="l2h-839"><tt class=method>postloop</tt></a></b> ()
<dd>
Hook method executed once when <tt class=method>cmdloop()</tt> is about to return.
This method is a stub in <tt class=class>Cmd</tt>; it exists to be overridden by
subclasses.
</dl>

<P>
Instances of <tt class=class>Cmd</tt> subclasses have some public instance variables:

<P>
<dl><dt><b><a name="l2h-840"><tt class=member>prompt</tt></a></b>
<dd>
The prompt issued to solicit input.
</dl>

<P>
<dl><dt><b><a name="l2h-841"><tt class=member>identchars</tt></a></b>
<dd>
The string of characters accepted for the command prefix.
</dl>

<P>
<dl><dt><b><a name="l2h-842"><tt class=member>lastcmd</tt></a></b>
<dd>
The last nonempty command prefix seen. 
</dl>

<P>
<dl><dt><b><a name="l2h-843"><tt class=member>intro</tt></a></b>
<dd>
A string to issue as an intro or banner.  May be overridden by giving
the <tt class=method>cmdloop()</tt> method an argument.
</dl>

<P>
<dl><dt><b><a name="l2h-844"><tt class=member>doc_header</tt></a></b>
<dd>
The header to issue if the help output has a section for documented
commands.
</dl>

<P>
<dl><dt><b><a name="l2h-845"><tt class=member>misc_header</tt></a></b>
<dd>
The header to issue if the help output has a section for miscellaneous 
help topics (that is, there are <tt class=method>help_*()</tt> methods without
corresponding <tt class=method>do_*()</tt> methods).
</dl>

<P>
<dl><dt><b><a name="l2h-846"><tt class=member>undoc_header</tt></a></b>
<dd>
The header to issue if the help output has a section for undocumented 
commands (that is, there are <tt class=method>do_*()</tt> methods without
corresponding <tt class=method>help_*()</tt> methods).
</dl>

<P>
<dl><dt><b><a name="l2h-847"><tt class=member>ruler</tt></a></b>
<dd>
The character used to draw separator lines under the help-message
headers.  If empty, no ruler line is drawn.  It defaults to
"<tt class=character>=</tt>".
</dl>

<P>
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-shlex.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-cmd.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-cmd.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-shlex.html">5.11 shlex  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-cmd.html">5.10 cmd  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-cmd.html">5.10 cmd  </A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
