Skip to content
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

bpo-37030: hide undocumented commands in cmd module #13536

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

aldwinaldwin
Copy link
Contributor

@aldwinaldwin aldwinaldwin commented May 24, 2019

A flag, defaulting to false. If true, :meth:do_help and :meth:completenames
won't include undocumented commands (that is, there are do_() methods without
corresponding help_
() methods).

https://bugs.python.org/issue37030

…enames

A flag, defaulting to false. If true, :meth:`do_help` and :meth:`completenames`
won't include undocumented commands (that is, there are do_*() methods without
corresponding help_*() methods).
Copy link
Member

@tirkarthi tirkarthi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left comment for doc and test. But in general would like to hear from a core dev on this.

return [a[3:] for a in self.get_names() if a.startswith(dotext)]
names = self.get_names()
commands = [a[3:] for a in names if a.startswith(dotext)]
if self.hide_undoc:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test similar to

>>> mycmd.completenames("a")
. In the doctest you can set mycmd.hide_undoc = True and make sure "shell" is not returned by the completenames function for "s". Set it mycmd.hide_undoc = False for rest of the tests to make sure to make sure other tests are not affected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, figured it out and made commit.

Doc/library/cmd.rst Show resolved Hide resolved
@aldwinaldwin aldwinaldwin changed the title bpo-37030: Lib/cmd.py: Hide undocumented commands bpo-37030: Lib/cmd.py: Hide undocumented commands. (GH-13536) May 31, 2019
@merwok merwok changed the title bpo-37030: Lib/cmd.py: Hide undocumented commands. (GH-13536) bpo-37030: hide undocumented commands in cmd mobule Jun 13, 2019
@vsajip vsajip changed the title bpo-37030: hide undocumented commands in cmd mobule bpo-37030: hide undocumented commands in cmd module Jun 19, 2019
@aldwinaldwin
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

: please review the changes made to this pull request.

kimbo added a commit to kimbo/cpython that referenced this pull request Nov 7, 2019
The current behavior of the cmd module is to return the string 'EOF'
when the program receives an EOF (e.g. when you press ctrl + d,
or when the end of a file is reached). When you're writing some kind of
REPL, you often want to exit when when you get an EOF (for example,
python's REPL exits when you press ctrl + d). The way to
achieve that functionality here is to create a function
called `do_EOF` in your subclass of `cmd.Cmd`, and call `exit()`
If you want some other behavior when you get an EOF, you can put
that in `do_EOF` instead.

This is problematic for two main reasons:

1. `EOF` shows up as an undocumented command when you type `help`. It's
not that big of a deal, but it's definitely not ideal (and perhaps
confusing).
2. If you type `EOF` into the terminal, it will call your `do_EOF`
function. If your `do_EOF` function exits, typing `do_EOF` will exit the
program. Seems rather silly.

I propose the cmd class NOT catch the EOFError. That will eliminate both
of the above problems. I realize this could be an issue with backwards
compatibility and such, but I don't think it would require much
adjustment (maybe a couple lines).

See also https://bugs.python.org/issue13214 and
python#13536
@rhettinger
Copy link
Contributor

Why would we want to encourage undocumented commands? This seems like an anti-pattern to me.

@aldwinaldwin
Copy link
Contributor Author

The reason was to have some secret functions for professional users or to have some try out functions that normal users would not start calling support about immediately. On the other had it bothered me that they are in the list to ask help for, while there is no help available for these anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants