[ruby/irb] Transform ls's --grep/-G option to keyword args
(https://github.com/ruby/irb/pull/437) * Transform ls's --grep/-G option to keyword args * Make --grep less flexible * Support -g instead of --grep * Suppress warnings from symbol aliases
This commit is contained in:
parent
d5513da01d
commit
8fa83fa0b2
@ -427,6 +427,7 @@ module IRB
|
|||||||
@context = Context.new(self, workspace, input_method)
|
@context = Context.new(self, workspace, input_method)
|
||||||
@context.main.extend ExtendCommandBundle
|
@context.main.extend ExtendCommandBundle
|
||||||
@context.command_aliases.each do |alias_name, cmd_name|
|
@context.command_aliases.each do |alias_name, cmd_name|
|
||||||
|
next if @context.symbol_alias(alias_name)
|
||||||
@context.main.install_alias_method(alias_name, cmd_name)
|
@context.main.install_alias_method(alias_name, cmd_name)
|
||||||
end
|
end
|
||||||
@signal_status = :IN_IRB
|
@signal_status = :IN_IRB
|
||||||
|
@ -9,6 +9,15 @@ module IRB
|
|||||||
|
|
||||||
module ExtendCommand
|
module ExtendCommand
|
||||||
class Ls < Nop
|
class Ls < Nop
|
||||||
|
def self.transform_args(args)
|
||||||
|
if match = args&.match(/\A(?<args>.+\s|)(-g|-G)\s+(?<grep>[^\s]+)\s*\n\z/)
|
||||||
|
args = match[:args]
|
||||||
|
"#{args}#{',' unless args.chomp.empty?} grep: /#{match[:grep]}/"
|
||||||
|
else
|
||||||
|
args
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def execute(*arg, grep: nil)
|
def execute(*arg, grep: nil)
|
||||||
o = Output.new(grep: grep)
|
o = Output.new(grep: grep)
|
||||||
|
|
||||||
|
@ -480,6 +480,44 @@ module TestIRB
|
|||||||
assert_match(/C.methods:\s+m5\n/m, out)
|
assert_match(/C.methods:\s+m5\n/m, out)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ls_grep
|
||||||
|
pend if RUBY_ENGINE == 'truffleruby'
|
||||||
|
out, err = execute_lines("ls 42\n")
|
||||||
|
assert_empty err
|
||||||
|
assert_match(/times/, out)
|
||||||
|
assert_match(/polar/, out)
|
||||||
|
|
||||||
|
[
|
||||||
|
"ls 42, grep: /times/\n",
|
||||||
|
"ls 42 -g times\n",
|
||||||
|
"ls 42 -G times\n",
|
||||||
|
].each do |line|
|
||||||
|
out, err = execute_lines(line)
|
||||||
|
assert_empty err
|
||||||
|
assert_match(/times/, out)
|
||||||
|
assert_not_match(/polar/, out)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ls_grep_empty
|
||||||
|
pend if RUBY_ENGINE == 'truffleruby'
|
||||||
|
out, err = execute_lines("ls\n")
|
||||||
|
assert_empty err
|
||||||
|
assert_match(/whereami/, out)
|
||||||
|
assert_match(/show_source/, out)
|
||||||
|
|
||||||
|
[
|
||||||
|
"ls grep: /whereami/\n",
|
||||||
|
"ls -g whereami\n",
|
||||||
|
"ls -G whereami\n",
|
||||||
|
].each do |line|
|
||||||
|
out, err = execute_lines(line)
|
||||||
|
assert_empty err
|
||||||
|
assert_match(/whereami/, out)
|
||||||
|
assert_not_match(/show_source/, out)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_ls_with_no_singleton_class
|
def test_ls_with_no_singleton_class
|
||||||
out, err = execute_lines(
|
out, err = execute_lines(
|
||||||
"ls 42",
|
"ls 42",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user