mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 21:14:23 +02:00

(https://github.com/ruby/irb/pull/877)
* Make help command display help for individual commands
Usage: `help [command]`
If the command is not specified, it will display a list of all available commands.
If the command is specified, it will display the banner OR description of the command.
If the command is not found, it will display a message saying that the command is not found.
* Rename test/irb/cmd to test/irb/command
* Add banner to edit and ls commands
* Promote help command in the help message
1. Make `show_cmds` an alias of `help` so it's not displayed in the help message
2. Update description of the help command to reflect `help <command>` syntax
* Rename banner to help_message
43a2c99f3f
102 lines
1.8 KiB
Ruby
102 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module IRB
|
|
class Statement
|
|
attr_reader :code
|
|
|
|
def is_assignment?
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def suppresses_echo?
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def should_be_handled_by_debugger?
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def evaluable_code
|
|
raise NotImplementedError
|
|
end
|
|
|
|
class EmptyInput < Statement
|
|
def is_assignment?
|
|
false
|
|
end
|
|
|
|
def suppresses_echo?
|
|
true
|
|
end
|
|
|
|
# Debugger takes empty input to repeat the last command
|
|
def should_be_handled_by_debugger?
|
|
true
|
|
end
|
|
|
|
def code
|
|
""
|
|
end
|
|
|
|
def evaluable_code
|
|
code
|
|
end
|
|
end
|
|
|
|
class Expression < Statement
|
|
def initialize(code, is_assignment)
|
|
@code = code
|
|
@is_assignment = is_assignment
|
|
end
|
|
|
|
def suppresses_echo?
|
|
@code.match?(/;\s*\z/)
|
|
end
|
|
|
|
def should_be_handled_by_debugger?
|
|
true
|
|
end
|
|
|
|
def is_assignment?
|
|
@is_assignment
|
|
end
|
|
|
|
def evaluable_code
|
|
@code
|
|
end
|
|
end
|
|
|
|
class Command < Statement
|
|
def initialize(code, command, arg, command_class)
|
|
@code = code
|
|
@command = command
|
|
@arg = arg
|
|
@command_class = command_class
|
|
end
|
|
|
|
def is_assignment?
|
|
false
|
|
end
|
|
|
|
def suppresses_echo?
|
|
false
|
|
end
|
|
|
|
def should_be_handled_by_debugger?
|
|
require_relative 'command/debug'
|
|
IRB::Command::DebugCommand > @command_class
|
|
end
|
|
|
|
def evaluable_code
|
|
# Hook command-specific transformation to return valid Ruby code
|
|
if @command_class.respond_to?(:transform_args)
|
|
arg = @command_class.transform_args(@arg)
|
|
else
|
|
arg = @arg
|
|
end
|
|
|
|
[@command, arg].compact.join(' ')
|
|
end
|
|
end
|
|
end
|
|
end
|