-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-37030: hide undocumented commands in cmd module #13536
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
base: main
Are you sure you want to change the base?
Conversation
…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).
There was a problem hiding this 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: |
There was a problem hiding this comment.
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
Line 55 in f1e17e9
>>> mycmd.completenames("a") |
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.
There was a problem hiding this comment.
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.
I have made the requested changes; please review again |
Thanks for making the requested changes! : please review the changes made to this pull request. |
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
Why would we want to encourage undocumented commands? This seems like an anti-pattern to me. |
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. |
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