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
2 changes: 1 addition & 1 deletion Lib/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def complete(self, text, state):
def get_names(self):
# This method used to pull in base class attributes
# at a time dir() didn't do it yet.
return dir(self.__class__)
return dir(self)

def complete_help(self, *args):
commands = set(self.completenames(*args))
Expand Down
37 changes: 37 additions & 0 deletions Lib/test/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,43 @@ def test_input_reset_at_EOF(self):
"(Cmd) \n"
"(Cmd) *** Unknown syntax: EOF\n"))

def test_dynamic_commands(self):
input = io.StringIO("help")
output = io.StringIO()
cmd = self.simplecmd(stdin=input, stdout=output)
cmd.use_rawinput = False
cmd.do_echo = lambda line: print(line)
cmd.cmdloop()
self.assertMultiLineEqual(output.getvalue(),
("(Cmd) \n"
"Documented commands (type help <topic>):\n"
"========================================\n"
"help\n"
"\n"
"Undocumented commands:\n"
"======================\n"
"EOF echo print\n"
"\n"
"(Cmd) "))

def test_dynamic_documentation(self):
input = io.StringIO("help")
output = io.StringIO()
cmd = self.simplecmd(stdin=input, stdout=output)
cmd.use_rawinput = False
cmd.help_print = lambda: print("documented")
cmd.cmdloop()
self.assertMultiLineEqual(output.getvalue(),
("(Cmd) \n"
"Documented commands (type help <topic>):\n"
"========================================\n"
"help print\n"
"\n"
"Undocumented commands:\n"
"======================\n"
"EOF\n"
"\n"
"(Cmd) "))

def test_main(verbose=None):
from test import test_cmd
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cmd.Cmd now support commands added directly to instances. Patch by Rémi
Lapeyre.