Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-143804: highlight default empty-line command repetition in cmd.Cmd documentation #143808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tanloong wants to merge 5 commits into python:main
base: main
Choose a base branch
Loading
from tanloong:cmd-emptyline
Open
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
View file Open in desktop
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
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /