Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Doc/library/cmd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ A :class:`Cmd` instance has the following methods:
are the beginning and ending indexes of the prefix text, which could be used to
provide different completion depending upon which position the argument is in.

.. rubric:: Empty input behavior

When the user enters an empty line in response to the prompt, ``Cmd`` does
**not** ignore the input by default. Instead, it repeats the last non-empty
command entered.

This behavior is implemented by :meth:`Cmd.emptyline`. Subclasses that do not
want empty input to repeat the previous command should override
:meth:`Cmd.emptyline` to do nothing::

def emptyline(self):
pass

.. method:: Cmd.do_help(arg)

Expand Down Expand Up @@ -127,6 +139,8 @@ A :class:`Cmd` instance has the following methods:
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.

Note that if :meth:`emptyline` is not overridden, empty input will cause
the previous command to be repeated and passed again to this method.

.. method:: Cmd.completedefault(text, line, begidx, endidx)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Clarified the documentation of :mod:`cmd` regarding the default handling of
empty input lines.
Loading