Improve help listing for regex aliases

This commit improves the appearance of regex aliases in the help index
by storing the result of calling #inspect on the regex as the listing.

For example, consider the `whereami` alias `/whereami[!?]+/`.
Previously this would appear in the help index as
`(?-mix:whereami[!?]+)`. This commit fixes this so it appears as
`/whereami[!?]+/`.
This commit is contained in:
Barrett Ingram 2020-03-22 14:43:20 -05:00
parent 0b3b71e714
commit a164846c4d
2 changed files with 7 additions and 2 deletions

View File

@ -193,7 +193,7 @@ class Pry
options = original_options.merge!(
desc: "Alias for `#{action}`",
listing: match
listing: match.is_a?(String) ? match : match.inspect
).merge!(options)
# ensure default description is used if desc is nil

View File

@ -185,11 +185,16 @@ RSpec.describe Pry::CommandSet do
expect(new_command.description).to eq('Alias for `test`')
end
it "sets aliased command's listing" do
it "sets aliased command's listing for string alias" do
new_command = subject.alias_command('new-test', 'test')
expect(new_command.options).to include(listing: 'new-test')
end
it "sets aliased command's listing for regex alias" do
new_command = subject.alias_command(/test[!?]+/, 'test')
expect(new_command.options[:listing].to_s).to eq('/test[!?]+/')
end
it "sets group for the aliased command automatically" do
new_command = subject.alias_command('new-test', 'test')
expect(new_command.group).to eq('Aliases')