Skip to content

Commit c8bba9f

Browse files
kachickst0012
andauthored
Avoid raising errors while running help for custom commands (#944)
* Avoid raising errors while running help for custom commands Raising an error from the help command is not a pleasure for the end user, even if the command does not define any attributes * Update test/irb/command/test_custom_command.rb --------- Co-authored-by: Stan Lo <stan001212@gmail.com>
1 parent f2b5fc1 commit c8bba9f

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎lib/irb/command/help.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def execute(command_name)
1212
help_message
1313
else
1414
if command_class = Command.load_command(command_name)
15-
command_class.help_message || command_class.description
15+
command_class.help_message || command_class.description || ""
1616
else
1717
"Can't find command `#{command_name}`. Please check the command name and try again.\n\n"
1818
end

‎test/irb/command/test_custom_command.rb‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,31 @@ def execute(*)
123123
assert_include(output, "2 FooBar executed")
124124
assert_include(output, "foobar_description")
125125
end
126+
127+
def test_no_meta_command_also_works
128+
write_ruby <<~RUBY
129+
require "irb/command"
130+
131+
class NoMetaCommand < IRB::Command::Base
132+
def execute(*)
133+
puts "This command does not override meta attributes"
134+
nil
135+
end
136+
end
137+
138+
IRB::Command.register(:no_meta, NoMetaCommand)
139+
140+
binding.irb
141+
RUBY
142+
143+
output = run_ruby_file do
144+
type "no_meta\n"
145+
type "help no_meta\n"
146+
type "exit"
147+
end
148+
149+
assert_include(output, "This command does not override meta attributes")
150+
assert_not_include(output, "Maybe IRB bug")
151+
end
126152
end
127153
end

0 commit comments

Comments
 (0)