From 3988d9aeb9a5b4782aaddb51ee9666733642ce32 Mon Sep 17 00:00:00 2001 From: Sam Denton Date: Tue, 3 May 2022 13:44:57 -0500 Subject: [PATCH 1/5] Update cmd.py sort the miscellaneous topics --- Lib/cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/cmd.py b/Lib/cmd.py index 859e91096d8f57..822c9c60f16673 100644 --- a/Lib/cmd.py +++ b/Lib/cmd.py @@ -332,7 +332,7 @@ def do_help(self, arg): cmds_undoc.append(cmd) self.stdout.write("%s\n"%str(self.doc_leader)) self.print_topics(self.doc_header, cmds_doc, 15,80) - self.print_topics(self.misc_header, list(help.keys()),15,80) + self.print_topics(self.misc_header, sorted(help.keys()),15,80) self.print_topics(self.undoc_header, cmds_undoc, 15,80) def print_topics(self, header, cmds, cmdlen, maxcol): From 9845f3f97b5ac8b1b1a3bd6d1cc281611a1d7e96 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 3 May 2022 19:06:39 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-05-03-19-06-38.gh-issue-67248.DK61Go.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-03-19-06-38.gh-issue-67248.DK61Go.rst diff --git a/Misc/NEWS.d/next/Library/2022-05-03-19-06-38.gh-issue-67248.DK61Go.rst b/Misc/NEWS.d/next/Library/2022-05-03-19-06-38.gh-issue-67248.DK61Go.rst new file mode 100644 index 00000000000000..8237934ccda00a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-03-19-06-38.gh-issue-67248.DK61Go.rst @@ -0,0 +1 @@ +Sort the miscellaneous topics in Cmd.do_help() From 30f4b6287860f567251f2ab861c09eca37f83f1f Mon Sep 17 00:00:00 2001 From: Sam Denton Date: Tue, 3 May 2022 15:30:57 -0500 Subject: [PATCH 3/5] Update cmd.py rename 'help' to 'topics', change it from a dict to a set --- Lib/cmd.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/cmd.py b/Lib/cmd.py index 822c9c60f16673..88ee7d3ddc4694 100644 --- a/Lib/cmd.py +++ b/Lib/cmd.py @@ -310,10 +310,10 @@ def do_help(self, arg): names = self.get_names() cmds_doc = [] cmds_undoc = [] - help = {} + topics = set() for name in names: if name[:5] == 'help_': - help[name[5:]]=1 + topics.add(name[5:]) names.sort() # There can be duplicates if routines overridden prevname = '' @@ -323,16 +323,16 @@ def do_help(self, arg): continue prevname = name cmd=name[3:] - if cmd in help: + if cmd in topics: cmds_doc.append(cmd) - del help[cmd] + topics.remove(cmd) elif getattr(self, name).__doc__: cmds_doc.append(cmd) else: cmds_undoc.append(cmd) self.stdout.write("%s\n"%str(self.doc_leader)) self.print_topics(self.doc_header, cmds_doc, 15,80) - self.print_topics(self.misc_header, sorted(help.keys()),15,80) + self.print_topics(self.misc_header, sorted(topics),15,80) self.print_topics(self.undoc_header, cmds_undoc, 15,80) def print_topics(self, header, cmds, cmdlen, maxcol): From 078665678858bb2148a260fb8ff59ea277429ac5 Mon Sep 17 00:00:00 2001 From: Sam Denton Date: Tue, 3 May 2022 15:33:53 -0500 Subject: [PATCH 4/5] Update test_cmd.py Add tests for miscellaneous help topics --- Lib/test/test_cmd.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_cmd.py b/Lib/test/test_cmd.py index 5e8b17c6e871a1..cd526441aa3811 100644 --- a/Lib/test/test_cmd.py +++ b/Lib/test/test_cmd.py @@ -70,7 +70,7 @@ class samplecmdclass(cmd.Cmd): >>> mycmd.complete_help("12") [] >>> sorted(mycmd.complete_help("")) - ['add', 'exit', 'help', 'shell'] + ['add', 'exit', 'help', 'meaning', 'shell'] Test for the function do_help(): >>> mycmd.do_help("testet") @@ -79,12 +79,20 @@ class samplecmdclass(cmd.Cmd): help text for add >>> mycmd.onecmd("help add") help text for add + >>> mycmd.onecmd("help meaning") # doctest: +NORMALIZE_WHITESPACE + Try and be nice to people, avoid eating fat, read a good book every + now and then, get some walking in, and try to live together in peace + and harmony with people of all creeds and nations. >>> mycmd.do_help("") Documented commands (type help ): ======================================== add help + Miscellaneous help topics: + ========================== + meaning + Undocumented commands: ====================== exit shell @@ -115,17 +123,22 @@ class samplecmdclass(cmd.Cmd): This test includes the preloop(), postloop(), default(), emptyline(), parseline(), do_help() functions >>> mycmd.use_rawinput=0 - >>> mycmd.cmdqueue=["", "add", "add 4 5", "help", "help add","exit"] - >>> mycmd.cmdloop() + + >>> mycmd.cmdqueue=["add", "add 4 5", "", "help", "help add", "exit"] + >>> mycmd.cmdloop() # doctest: +REPORT_NDIFF Hello from preloop - help text for add *** invalid number of arguments 9 + 9 Documented commands (type help ): ======================================== add help + Miscellaneous help topics: + ========================== + meaning + Undocumented commands: ====================== exit shell @@ -165,6 +178,13 @@ def help_add(self): print("help text for add") return + def help_meaning(self): + print("Try and be nice to people, avoid eating fat, read a " + "good book every now and then, get some walking in, " + "and try to live together in peace and harmony with " + "people of all creeds and nations.") + return + def do_exit(self, arg): return True From 151677734cc0863c03f7f225a54c00a5631d7e18 Mon Sep 17 00:00:00 2001 From: Sam Denton Date: Tue, 3 May 2022 16:24:11 -0500 Subject: [PATCH 5/5] Update test_cmd.py add a second misc topic to test sorting also, the empty command tested with mycmd.cmdloop() was repeating a command issued with mycmd.onecmd(), so I moved it into the middle of the list of commands, to make the output more dependable. --- Lib/test/test_cmd.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_cmd.py b/Lib/test/test_cmd.py index cd526441aa3811..319801c71f776b 100644 --- a/Lib/test/test_cmd.py +++ b/Lib/test/test_cmd.py @@ -70,7 +70,7 @@ class samplecmdclass(cmd.Cmd): >>> mycmd.complete_help("12") [] >>> sorted(mycmd.complete_help("")) - ['add', 'exit', 'help', 'meaning', 'shell'] + ['add', 'exit', 'help', 'life', 'meaning', 'shell'] Test for the function do_help(): >>> mycmd.do_help("testet") @@ -91,7 +91,7 @@ class samplecmdclass(cmd.Cmd): Miscellaneous help topics: ========================== - meaning + life meaning Undocumented commands: ====================== @@ -137,7 +137,7 @@ class samplecmdclass(cmd.Cmd): Miscellaneous help topics: ========================== - meaning + life meaning Undocumented commands: ====================== @@ -185,6 +185,10 @@ def help_meaning(self): "people of all creeds and nations.") return + def help_life(self): + print("Always look on the bright side of life") + return + def do_exit(self, arg): return True