Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize command related names #873

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
55 changes: 3 additions & 52 deletions lib/irb/cmd/nop.rb
Original file line number Diff line number Diff line change
@@ -1,53 +1,4 @@
# frozen_string_literal: false
#
# nop.rb -
# by Keiju ISHITSUKA([email protected])
#
# 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.
85 changes: 45 additions & 40 deletions lib/irb/extend-command.rb → lib/irb/command.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# frozen_string_literal: false
#
# irb/extend-command.rb - irb extend command
# irb/command.rb - irb command
# by Keiju ISHITSUKA([email protected])
#

require_relative "command/base"

module IRB # :nodoc:
module Command; end
ExtendCommand = Command

# Installs the default irb extensions command bundle.
module ExtendCommandBundle
EXCB = ExtendCommandBundle # :nodoc:
Expand All @@ -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],
Expand 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],
Expand All @@ -65,21 +70,21 @@ 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],
[:irb_pushb, OVERRIDE_ALL],
[: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],
Expand 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],
]
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/irb/cmd/backtrace.rb → lib/irb/command/backtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module IRB
# :stopdoc:

module ExtendCommand
module Command
class Backtrace < DebugCommand
def self.transform_args(args)
args&.dump
Expand Down
55 changes: 55 additions & 0 deletions lib/irb/command/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: false
#
# nop.rb -
# by Keiju ISHITSUKA([email protected])
#

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
2 changes: 1 addition & 1 deletion lib/irb/cmd/break.rb → lib/irb/command/break.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module IRB
# :stopdoc:

module ExtendCommand
module Command
class Break < DebugCommand
def self.transform_args(args)
args&.dump
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/cmd/catch.rb → lib/irb/command/catch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module IRB
# :stopdoc:

module ExtendCommand
module Command
class Catch < DebugCommand
def self.transform_args(args)
args&.dump
Expand Down
Loading
Loading