diff --git a/lib/irb.rb b/lib/irb.rb index fd06626e9..73d96947e 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -9,7 +9,7 @@ require_relative "irb/init" require_relative "irb/context" -require_relative "irb/extend-command" +require_relative "irb/command" require_relative "irb/ruby-lex" require_relative "irb/statement" diff --git a/lib/irb/cmd/nop.rb b/lib/irb/cmd/nop.rb index 7fb197c51..49f89bac9 100644 --- a/lib/irb/cmd/nop.rb +++ b/lib/irb/cmd/nop.rb @@ -1,53 +1,4 @@ -# frozen_string_literal: false -# -# nop.rb - -# by Keiju ISHITSUKA(keiju@ruby-lang.org) -# +# frozen_string_literal: true -module IRB - # :stopdoc: - - module ExtendCommand - class CommandArgumentError < StandardError; end - - class Nop - class << self - def category(category = nil) - @category = category if category - @category - end - - def description(description = nil) - @description = description if description - @description - end - - private - - def string_literal?(args) - sexp = Ripper.sexp(args) - sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal - end - end - - def self.execute(irb_context, *opts, **kwargs, &block) - command = new(irb_context) - command.execute(*opts, **kwargs, &block) - rescue CommandArgumentError => e - puts e.message - end - - def initialize(irb_context) - @irb_context = irb_context - end - - attr_reader :irb_context - - def execute(*opts) - #nop - end - end - end - - # :startdoc: -end +# This file is just a placeholder for backward-compatibility. +# Please require 'irb' and inheirt your command from `IRB::Command::Base` instead. diff --git a/lib/irb/extend-command.rb b/lib/irb/command.rb similarity index 78% rename from lib/irb/extend-command.rb rename to lib/irb/command.rb index d303bf76d..cab571cfe 100644 --- a/lib/irb/extend-command.rb +++ b/lib/irb/command.rb @@ -1,10 +1,15 @@ # frozen_string_literal: false # -# irb/extend-command.rb - irb extend command +# irb/command.rb - irb command # by Keiju ISHITSUKA(keiju@ruby-lang.org) # +require_relative "command/base" + module IRB # :nodoc: + module Command; end + ExtendCommand = Command + # Installs the default irb extensions command bundle. module ExtendCommandBundle EXCB = ExtendCommandBundle # :nodoc: @@ -31,18 +36,18 @@ def irb_context @EXTEND_COMMANDS = [ [ - :irb_exit, :Exit, "cmd/exit", + :irb_exit, :Exit, "command/exit", [:exit, OVERRIDE_PRIVATE_ONLY], [:quit, OVERRIDE_PRIVATE_ONLY], [:irb_quit, OVERRIDE_PRIVATE_ONLY], ], [ - :irb_exit!, :ForceExit, "cmd/force_exit", + :irb_exit!, :ForceExit, "command/force_exit", [:exit!, OVERRIDE_PRIVATE_ONLY], ], [ - :irb_current_working_workspace, :CurrentWorkingWorkspace, "cmd/chws", + :irb_current_working_workspace, :CurrentWorkingWorkspace, "command/chws", [:cwws, NO_OVERRIDE], [:pwws, NO_OVERRIDE], [:irb_print_working_workspace, OVERRIDE_ALL], @@ -54,7 +59,7 @@ def irb_context [:irb_pwb, OVERRIDE_ALL], ], [ - :irb_change_workspace, :ChangeWorkspace, "cmd/chws", + :irb_change_workspace, :ChangeWorkspace, "command/chws", [:chws, NO_OVERRIDE], [:cws, NO_OVERRIDE], [:irb_chws, OVERRIDE_ALL], @@ -65,13 +70,13 @@ def irb_context ], [ - :irb_workspaces, :Workspaces, "cmd/pushws", + :irb_workspaces, :Workspaces, "command/pushws", [:workspaces, NO_OVERRIDE], [:irb_bindings, OVERRIDE_ALL], [:bindings, NO_OVERRIDE], ], [ - :irb_push_workspace, :PushWorkspace, "cmd/pushws", + :irb_push_workspace, :PushWorkspace, "command/pushws", [:pushws, NO_OVERRIDE], [:irb_pushws, OVERRIDE_ALL], [:irb_push_binding, OVERRIDE_ALL], @@ -79,7 +84,7 @@ def irb_context [:pushb, NO_OVERRIDE], ], [ - :irb_pop_workspace, :PopWorkspace, "cmd/pushws", + :irb_pop_workspace, :PopWorkspace, "command/pushws", [:popws, NO_OVERRIDE], [:irb_popws, OVERRIDE_ALL], [:irb_pop_binding, OVERRIDE_ALL], @@ -88,112 +93,112 @@ def irb_context ], [ - :irb_load, :Load, "cmd/load"], + :irb_load, :Load, "command/load"], [ - :irb_require, :Require, "cmd/load"], + :irb_require, :Require, "command/load"], [ - :irb_source, :Source, "cmd/load", + :irb_source, :Source, "command/load", [:source, NO_OVERRIDE], ], [ - :irb, :IrbCommand, "cmd/subirb"], + :irb, :IrbCommand, "command/subirb"], [ - :irb_jobs, :Jobs, "cmd/subirb", + :irb_jobs, :Jobs, "command/subirb", [:jobs, NO_OVERRIDE], ], [ - :irb_fg, :Foreground, "cmd/subirb", + :irb_fg, :Foreground, "command/subirb", [:fg, NO_OVERRIDE], ], [ - :irb_kill, :Kill, "cmd/subirb", + :irb_kill, :Kill, "command/subirb", [:kill, OVERRIDE_PRIVATE_ONLY], ], [ - :irb_debug, :Debug, "cmd/debug", + :irb_debug, :Debug, "command/debug", [:debug, NO_OVERRIDE], ], [ - :irb_edit, :Edit, "cmd/edit", + :irb_edit, :Edit, "command/edit", [:edit, NO_OVERRIDE], ], [ - :irb_break, :Break, "cmd/break", + :irb_break, :Break, "command/break", ], [ - :irb_catch, :Catch, "cmd/catch", + :irb_catch, :Catch, "command/catch", ], [ - :irb_next, :Next, "cmd/next" + :irb_next, :Next, "command/next" ], [ - :irb_delete, :Delete, "cmd/delete", + :irb_delete, :Delete, "command/delete", [:delete, NO_OVERRIDE], ], [ - :irb_step, :Step, "cmd/step", + :irb_step, :Step, "command/step", [:step, NO_OVERRIDE], ], [ - :irb_continue, :Continue, "cmd/continue", + :irb_continue, :Continue, "command/continue", [:continue, NO_OVERRIDE], ], [ - :irb_finish, :Finish, "cmd/finish", + :irb_finish, :Finish, "command/finish", [:finish, NO_OVERRIDE], ], [ - :irb_backtrace, :Backtrace, "cmd/backtrace", + :irb_backtrace, :Backtrace, "command/backtrace", [:backtrace, NO_OVERRIDE], [:bt, NO_OVERRIDE], ], [ - :irb_debug_info, :Info, "cmd/info", + :irb_debug_info, :Info, "command/info", [:info, NO_OVERRIDE], ], [ - :irb_help, :Help, "cmd/help", + :irb_help, :Help, "command/help", [:help, NO_OVERRIDE], ], [ - :irb_show_doc, :ShowDoc, "cmd/show_doc", + :irb_show_doc, :ShowDoc, "command/show_doc", [:show_doc, NO_OVERRIDE], ], [ - :irb_info, :IrbInfo, "cmd/irb_info" + :irb_info, :IrbInfo, "command/irb_info" ], [ - :irb_ls, :Ls, "cmd/ls", + :irb_ls, :Ls, "command/ls", [:ls, NO_OVERRIDE], ], [ - :irb_measure, :Measure, "cmd/measure", + :irb_measure, :Measure, "command/measure", [:measure, NO_OVERRIDE], ], [ - :irb_show_source, :ShowSource, "cmd/show_source", + :irb_show_source, :ShowSource, "command/show_source", [:show_source, NO_OVERRIDE], ], [ - :irb_whereami, :Whereami, "cmd/whereami", + :irb_whereami, :Whereami, "command/whereami", [:whereami, NO_OVERRIDE], ], [ - :irb_show_cmds, :ShowCmds, "cmd/show_cmds", + :irb_show_cmds, :ShowCmds, "command/show_cmds", [:show_cmds, NO_OVERRIDE], ], [ - :irb_history, :History, "cmd/history", + :irb_history, :History, "command/history", [:history, NO_OVERRIDE], [:hist, NO_OVERRIDE], ] @@ -210,11 +215,11 @@ def self.all_commands_info end @EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases| - if !defined?(ExtendCommand) || !ExtendCommand.const_defined?(cmd_class, false) + if !defined?(Command) || !Command.const_defined?(cmd_class, false) require_relative load_file end - klass = ExtendCommand.const_get(cmd_class, false) + klass = Command.const_get(cmd_class, false) aliases = aliases.map { |a| a.first } if additional_aliases = user_aliases[cmd_name] @@ -234,10 +239,10 @@ def self.load_command(command) @EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases| next if cmd_name != command && aliases.all? { |alias_name, _| alias_name != command } - if !defined?(ExtendCommand) || !ExtendCommand.const_defined?(cmd_class, false) + if !defined?(Command) || !Command.const_defined?(cmd_class, false) require_relative load_file end - return ExtendCommand.const_get(cmd_class, false) + return Command.const_get(cmd_class, false) end nil end @@ -267,7 +272,7 @@ def self.def_extend_command(cmd_name, cmd_class, load_file, *aliases) line = __LINE__; eval %[ def #{cmd_name}(*opts, **kwargs, &b) Kernel.require_relative "#{load_file}" - ::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, *opts, **kwargs, &b) + ::IRB::Command::#{cmd_class}.execute(irb_context, *opts, **kwargs, &b) end ], nil, __FILE__, line diff --git a/lib/irb/cmd/backtrace.rb b/lib/irb/command/backtrace.rb similarity index 93% rename from lib/irb/cmd/backtrace.rb rename to lib/irb/command/backtrace.rb index f63289461..47e5e6072 100644 --- a/lib/irb/cmd/backtrace.rb +++ b/lib/irb/command/backtrace.rb @@ -5,7 +5,7 @@ module IRB # :stopdoc: - module ExtendCommand + module Command class Backtrace < DebugCommand def self.transform_args(args) args&.dump diff --git a/lib/irb/command/base.rb b/lib/irb/command/base.rb new file mode 100644 index 000000000..87d2fea35 --- /dev/null +++ b/lib/irb/command/base.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: false +# +# nop.rb - +# by Keiju ISHITSUKA(keiju@ruby-lang.org) +# + +module IRB + # :stopdoc: + + module Command + class CommandArgumentError < StandardError; end + + class Base + class << self + def category(category = nil) + @category = category if category + @category + end + + def description(description = nil) + @description = description if description + @description + end + + private + + def string_literal?(args) + sexp = Ripper.sexp(args) + sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal + end + end + + def self.execute(irb_context, *opts, **kwargs, &block) + command = new(irb_context) + command.execute(*opts, **kwargs, &block) + rescue CommandArgumentError => e + puts e.message + end + + def initialize(irb_context) + @irb_context = irb_context + end + + attr_reader :irb_context + + def execute(*opts) + #nop + end + end + + Nop = Base + end + + # :startdoc: +end diff --git a/lib/irb/cmd/break.rb b/lib/irb/command/break.rb similarity index 92% rename from lib/irb/cmd/break.rb rename to lib/irb/command/break.rb index df259a90c..fa200f2d7 100644 --- a/lib/irb/cmd/break.rb +++ b/lib/irb/command/break.rb @@ -5,7 +5,7 @@ module IRB # :stopdoc: - module ExtendCommand + module Command class Break < DebugCommand def self.transform_args(args) args&.dump diff --git a/lib/irb/cmd/catch.rb b/lib/irb/command/catch.rb similarity index 92% rename from lib/irb/cmd/catch.rb rename to lib/irb/command/catch.rb index 40b62c753..6b2edff5e 100644 --- a/lib/irb/cmd/catch.rb +++ b/lib/irb/command/catch.rb @@ -5,7 +5,7 @@ module IRB # :stopdoc: - module ExtendCommand + module Command class Catch < DebugCommand def self.transform_args(args) args&.dump diff --git a/lib/irb/cmd/chws.rb b/lib/irb/command/chws.rb similarity index 81% rename from lib/irb/cmd/chws.rb rename to lib/irb/command/chws.rb index 31045f9bb..341d51615 100644 --- a/lib/irb/cmd/chws.rb +++ b/lib/irb/command/chws.rb @@ -3,16 +3,14 @@ # change-ws.rb - # by Keiju ISHITSUKA(keiju@ruby-lang.org) # - -require_relative "nop" require_relative "../ext/change-ws" module IRB # :stopdoc: - module ExtendCommand + module Command - class CurrentWorkingWorkspace < Nop + class CurrentWorkingWorkspace < Base category "Workspace" description "Show the current workspace." @@ -21,7 +19,7 @@ def execute(*obj) end end - class ChangeWorkspace < Nop + class ChangeWorkspace < Base category "Workspace" description "Change the current workspace to an object." diff --git a/lib/irb/cmd/continue.rb b/lib/irb/command/continue.rb similarity index 91% rename from lib/irb/cmd/continue.rb rename to lib/irb/command/continue.rb index 9136177ee..8b6ffc860 100644 --- a/lib/irb/cmd/continue.rb +++ b/lib/irb/command/continue.rb @@ -5,7 +5,7 @@ module IRB # :stopdoc: - module ExtendCommand + module Command class Continue < DebugCommand def execute(*args) super(do_cmds: ["continue", *args].join(" ")) diff --git a/lib/irb/cmd/debug.rb b/lib/irb/command/debug.rb similarity index 97% rename from lib/irb/cmd/debug.rb rename to lib/irb/command/debug.rb index f5c985f07..bdf91766b 100644 --- a/lib/irb/cmd/debug.rb +++ b/lib/irb/command/debug.rb @@ -1,11 +1,10 @@ -require_relative "nop" require_relative "../debug" module IRB # :stopdoc: - module ExtendCommand - class Debug < Nop + module Command + class Debug < Base category "Debugging" description "Start the debugger of debug.gem." diff --git a/lib/irb/cmd/delete.rb b/lib/irb/command/delete.rb similarity index 91% rename from lib/irb/cmd/delete.rb rename to lib/irb/command/delete.rb index aeb26d257..a36b4577b 100644 --- a/lib/irb/cmd/delete.rb +++ b/lib/irb/command/delete.rb @@ -5,7 +5,7 @@ module IRB # :stopdoc: - module ExtendCommand + module Command class Delete < DebugCommand def execute(*args) super(pre_cmds: ["delete", *args].join(" ")) diff --git a/lib/irb/cmd/edit.rb b/lib/irb/command/edit.rb similarity index 95% rename from lib/irb/cmd/edit.rb rename to lib/irb/command/edit.rb index dae65f3c3..1a8ded6bc 100644 --- a/lib/irb/cmd/edit.rb +++ b/lib/irb/command/edit.rb @@ -1,12 +1,12 @@ require 'shellwords' -require_relative "nop" + require_relative "../source_finder" module IRB # :stopdoc: - module ExtendCommand - class Edit < Nop + module Command + class Edit < Base category "Misc" description 'Open a file with the editor command defined with `ENV["VISUAL"]` or `ENV["EDITOR"]`.' diff --git a/lib/irb/cmd/exit.rb b/lib/irb/command/exit.rb similarity index 79% rename from lib/irb/cmd/exit.rb rename to lib/irb/command/exit.rb index 415e55533..3109ec16e 100644 --- a/lib/irb/cmd/exit.rb +++ b/lib/irb/command/exit.rb @@ -1,12 +1,10 @@ # frozen_string_literal: true -require_relative "nop" - module IRB # :stopdoc: - module ExtendCommand - class Exit < Nop + module Command + class Exit < Base category "IRB" description "Exit the current irb session." diff --git a/lib/irb/cmd/finish.rb b/lib/irb/command/finish.rb similarity index 91% rename from lib/irb/cmd/finish.rb rename to lib/irb/command/finish.rb index 29f100feb..05501819e 100644 --- a/lib/irb/cmd/finish.rb +++ b/lib/irb/command/finish.rb @@ -5,7 +5,7 @@ module IRB # :stopdoc: - module ExtendCommand + module Command class Finish < DebugCommand def execute(*args) super(do_cmds: ["finish", *args].join(" ")) diff --git a/lib/irb/cmd/force_exit.rb b/lib/irb/command/force_exit.rb similarity index 78% rename from lib/irb/cmd/force_exit.rb rename to lib/irb/command/force_exit.rb index 7e9b308de..c2c5542e2 100644 --- a/lib/irb/cmd/force_exit.rb +++ b/lib/irb/command/force_exit.rb @@ -1,12 +1,10 @@ # frozen_string_literal: true -require_relative "nop" - module IRB # :stopdoc: - module ExtendCommand - class ForceExit < Nop + module Command + class ForceExit < Base category "IRB" description "Exit the current process." diff --git a/lib/irb/cmd/help.rb b/lib/irb/command/help.rb similarity index 90% rename from lib/irb/cmd/help.rb rename to lib/irb/command/help.rb index 7f894688c..67cc31a0b 100644 --- a/lib/irb/cmd/help.rb +++ b/lib/irb/command/help.rb @@ -3,7 +3,7 @@ require_relative "show_cmds" module IRB - module ExtendCommand + module Command class Help < ShowCmds category "IRB" description "List all available commands and their description." diff --git a/lib/irb/cmd/history.rb b/lib/irb/command/history.rb similarity index 94% rename from lib/irb/cmd/history.rb rename to lib/irb/command/history.rb index 5b712fa44..a47a8795d 100644 --- a/lib/irb/cmd/history.rb +++ b/lib/irb/command/history.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true require "stringio" -require_relative "nop" + require_relative "../pager" module IRB # :stopdoc: - module ExtendCommand - class History < Nop + module Command + class History < Base category "IRB" description "Shows the input history. `-g [query]` or `-G [query]` allows you to filter the output." diff --git a/lib/irb/cmd/info.rb b/lib/irb/command/info.rb similarity index 92% rename from lib/irb/cmd/info.rb rename to lib/irb/command/info.rb index 2c0a32b34..a67be3eb8 100644 --- a/lib/irb/cmd/info.rb +++ b/lib/irb/command/info.rb @@ -5,7 +5,7 @@ module IRB # :stopdoc: - module ExtendCommand + module Command class Info < DebugCommand def self.transform_args(args) args&.dump diff --git a/lib/irb/cmd/irb_info.rb b/lib/irb/command/irb_info.rb similarity index 93% rename from lib/irb/cmd/irb_info.rb rename to lib/irb/command/irb_info.rb index 5b905a09b..7fd3e2104 100644 --- a/lib/irb/cmd/irb_info.rb +++ b/lib/irb/command/irb_info.rb @@ -1,12 +1,10 @@ # frozen_string_literal: false -require_relative "nop" - module IRB # :stopdoc: - module ExtendCommand - class IrbInfo < Nop + module Command + class IrbInfo < Base category "IRB" description "Show information about IRB." diff --git a/lib/irb/cmd/load.rb b/lib/irb/command/load.rb similarity index 95% rename from lib/irb/cmd/load.rb rename to lib/irb/command/load.rb index a3e797a7e..0558bc83b 100644 --- a/lib/irb/cmd/load.rb +++ b/lib/irb/command/load.rb @@ -3,15 +3,13 @@ # load.rb - # by Keiju ISHITSUKA(keiju@ruby-lang.org) # - -require_relative "nop" require_relative "../ext/loader" module IRB # :stopdoc: - module ExtendCommand - class LoaderCommand < Nop + module Command + class LoaderCommand < Base include IrbLoader def raise_cmd_argument_error diff --git a/lib/irb/cmd/ls.rb b/lib/irb/command/ls.rb similarity index 98% rename from lib/irb/cmd/ls.rb rename to lib/irb/command/ls.rb index 791b1c1b2..bbe4a1ee9 100644 --- a/lib/irb/cmd/ls.rb +++ b/lib/irb/command/ls.rb @@ -2,15 +2,15 @@ require "reline" require "stringio" -require_relative "nop" + require_relative "../pager" require_relative "../color" module IRB # :stopdoc: - module ExtendCommand - class Ls < Nop + module Command + class Ls < Base category "Context" description "Show methods, constants, and variables. `-g [query]` or `-G [query]` allows you to filter out the output." diff --git a/lib/irb/cmd/measure.rb b/lib/irb/command/measure.rb similarity index 94% rename from lib/irb/cmd/measure.rb rename to lib/irb/command/measure.rb index 4e1125a0a..ee7927b01 100644 --- a/lib/irb/cmd/measure.rb +++ b/lib/irb/command/measure.rb @@ -1,10 +1,8 @@ -require_relative "nop" - module IRB # :stopdoc: - module ExtendCommand - class Measure < Nop + module Command + class Measure < Base category "Misc" description "`measure` enables the mode to measure processing time. `measure :off` disables it." diff --git a/lib/irb/cmd/next.rb b/lib/irb/command/next.rb similarity index 90% rename from lib/irb/cmd/next.rb rename to lib/irb/command/next.rb index d29c82e7f..6487c9d24 100644 --- a/lib/irb/cmd/next.rb +++ b/lib/irb/command/next.rb @@ -5,7 +5,7 @@ module IRB # :stopdoc: - module ExtendCommand + module Command class Next < DebugCommand def execute(*args) super(do_cmds: ["next", *args].join(" ")) diff --git a/lib/irb/cmd/pushws.rb b/lib/irb/command/pushws.rb similarity index 91% rename from lib/irb/cmd/pushws.rb rename to lib/irb/command/pushws.rb index 59996ceb0..a6fcd6a16 100644 --- a/lib/irb/cmd/pushws.rb +++ b/lib/irb/command/pushws.rb @@ -4,14 +4,13 @@ # by Keiju ISHITSUKA(keiju@ruby-lang.org) # -require_relative "nop" require_relative "../ext/workspaces" module IRB # :stopdoc: - module ExtendCommand - class Workspaces < Nop + module Command + class Workspaces < Base category "Workspace" description "Show workspaces." diff --git a/lib/irb/cmd/show_cmds.rb b/lib/irb/command/show_cmds.rb similarity index 96% rename from lib/irb/cmd/show_cmds.rb rename to lib/irb/command/show_cmds.rb index a8d899e4a..940ed490d 100644 --- a/lib/irb/cmd/show_cmds.rb +++ b/lib/irb/command/show_cmds.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true require "stringio" -require_relative "nop" + require_relative "../pager" module IRB # :stopdoc: - module ExtendCommand - class ShowCmds < Nop + module Command + class ShowCmds < Base category "IRB" description "List all available commands and their description." diff --git a/lib/irb/cmd/show_doc.rb b/lib/irb/command/show_doc.rb similarity index 93% rename from lib/irb/cmd/show_doc.rb rename to lib/irb/command/show_doc.rb index 99dd9ab95..dca10ec4b 100644 --- a/lib/irb/cmd/show_doc.rb +++ b/lib/irb/command/show_doc.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true -require_relative "nop" - module IRB - module ExtendCommand - class ShowDoc < Nop + module Command + class ShowDoc < Base class << self def transform_args(args) # Return a string literal as is for backward compatibility diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/command/show_source.rb similarity index 95% rename from lib/irb/cmd/show_source.rb rename to lib/irb/command/show_source.rb index cd07de3e9..cc783e753 100644 --- a/lib/irb/cmd/show_source.rb +++ b/lib/irb/command/show_source.rb @@ -1,13 +1,12 @@ # frozen_string_literal: true -require_relative "nop" require_relative "../source_finder" require_relative "../pager" require_relative "../color" module IRB - module ExtendCommand - class ShowSource < Nop + module Command + class ShowSource < Base category "Context" description "Show the source code of a given method or constant." diff --git a/lib/irb/cmd/step.rb b/lib/irb/command/step.rb similarity index 90% rename from lib/irb/cmd/step.rb rename to lib/irb/command/step.rb index 2bc74a9d7..cce7d2b0f 100644 --- a/lib/irb/cmd/step.rb +++ b/lib/irb/command/step.rb @@ -5,7 +5,7 @@ module IRB # :stopdoc: - module ExtendCommand + module Command class Step < DebugCommand def execute(*args) super(do_cmds: ["step", *args].join(" ")) diff --git a/lib/irb/cmd/subirb.rb b/lib/irb/command/subirb.rb similarity index 96% rename from lib/irb/cmd/subirb.rb rename to lib/irb/command/subirb.rb index 5ffd64641..0a75706f5 100644 --- a/lib/irb/cmd/subirb.rb +++ b/lib/irb/command/subirb.rb @@ -4,13 +4,11 @@ # by Keiju ISHITSUKA(keiju@ruby-lang.org) # -require_relative "nop" - module IRB # :stopdoc: - module ExtendCommand - class MultiIRBCommand < Nop + module Command + class MultiIRBCommand < Base def execute(*args) extend_irb_context end diff --git a/lib/irb/cmd/whereami.rb b/lib/irb/command/whereami.rb similarity index 84% rename from lib/irb/cmd/whereami.rb rename to lib/irb/command/whereami.rb index 8f56ba073..d6658d704 100644 --- a/lib/irb/cmd/whereami.rb +++ b/lib/irb/command/whereami.rb @@ -1,12 +1,10 @@ # frozen_string_literal: true -require_relative "nop" - module IRB # :stopdoc: - module ExtendCommand - class Whereami < Nop + module Command + class Whereami < Base category "Context" description "Show the source code around binding.irb again." diff --git a/lib/irb/ext/use-loader.rb b/lib/irb/ext/use-loader.rb index d0b8c2d4f..c5ecbe284 100644 --- a/lib/irb/ext/use-loader.rb +++ b/lib/irb/ext/use-loader.rb @@ -17,12 +17,12 @@ module ExtendCommandBundle remove_method :irb_load if method_defined?(:irb_load) # Loads the given file similarly to Kernel#load, see IrbLoader#irb_load def irb_load(*opts, &b) - ExtendCommand::Load.execute(irb_context, *opts, &b) + Command::Load.execute(irb_context, *opts, &b) end remove_method :irb_require if method_defined?(:irb_require) # Loads the given file similarly to Kernel#require def irb_require(*opts, &b) - ExtendCommand::Require.execute(irb_context, *opts, &b) + Command::Require.execute(irb_context, *opts, &b) end end diff --git a/lib/irb/statement.rb b/lib/irb/statement.rb index 4e17e5143..009eb2d20 100644 --- a/lib/irb/statement.rb +++ b/lib/irb/statement.rb @@ -83,9 +83,9 @@ def suppresses_echo? end def should_be_handled_by_debugger? - require_relative 'cmd/help' - require_relative 'cmd/debug' - IRB::ExtendCommand::DebugCommand > @command_class || IRB::ExtendCommand::Help == @command_class + require_relative 'command/help' + require_relative 'command/debug' + IRB::Command::DebugCommand > @command_class || IRB::Command::Help == @command_class end def evaluable_code diff --git a/test/irb/test_cmd.rb b/test/irb/test_command.rb similarity index 99% rename from test/irb/test_cmd.rb rename to test/irb/test_command.rb index b9a155ec0..15ae6a658 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_command.rb @@ -1,7 +1,6 @@ # frozen_string_literal: false require "rubygems" require "irb" -require "irb/extend-command" require_relative "helper" @@ -797,7 +796,7 @@ def test_show_doc assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the `show_doc` command to match one of the possible outputs. Got:\n#{out}") 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" } + EnvUtil.suppress_warning { load "irb/command/help.rb" } end def test_show_doc_without_rdoc @@ -813,7 +812,7 @@ def test_show_doc_without_rdoc assert_include(err, "Can't display document because `rdoc` is not installed.\n") 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" } + EnvUtil.suppress_warning { load "irb/command/help.rb" } end end