[ruby/irb] Add show_doc as an alias to the help command

(https://github.com/ruby/irb/pull/475)

In the long-term, we want to align with `Pry`, `byebug` and `debug` to
use the `help` command to list all commands, which is what `show_cmds`
currently does. And `show_doc` will be the command to look up Ruby APIs.

By aliasing `show_doc` to the current `help` now, users will have time
to get use to it.
This commit is contained in:
Stan Lo 2022-12-08 21:46:51 +00:00 коммит произвёл git
Родитель 12b7c129bf
Коммит c9076d546a
2 изменённых файлов: 12 добавлений и 9 удалений

Просмотреть файл

@ -162,6 +162,7 @@ module IRB # :nodoc:
[
:irb_help, :Help, "cmd/help",
[:show_doc, NO_OVERRIDE],
[:help, NO_OVERRIDE],
],

Просмотреть файл

@ -376,16 +376,18 @@ module TestIRB
assert_match(/Please specify the file name./, out)
end
def test_help
out, _ = execute_lines(
"help 'String#gsub'\n",
"\n",
)
def test_help_and_show_doc
["help", "show_doc"].each do |cmd|
out, _ = execute_lines(
"#{cmd} 'String#gsub'\n",
"\n",
)
# the former is what we'd get without document content installed, like on CI
# the latter is what we may get locally
possible_rdoc_output = [/Nothing known about String#gsub/, /Returns a copy of self with all occurrences of the given pattern/]
assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the help command to match one of the possible outputs")
# the former is what we'd get without document content installed, like on CI
# the latter is what we may get locally
possible_rdoc_output = [/Nothing known about String#gsub/, /Returns a copy of self with all occurrences of the given pattern/]
assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the `#{cmd}` command to match one of the possible outputs")
end
ensure
# this is the only way to reset the redefined method without coupling the test with its implementation
EnvUtil.suppress_warning { load "irb/cmd/help.rb" }