Skip to content
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/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def normalize_command_name(meth) #:nodoc:
# alias name.
def find_command_possibilities(meth)
len = meth.to_s.length
possibilities = all_commands.merge(map).keys.select { |n| meth == n[0, len] }.sort
possibilities = all_commands.reject {|k, v| v.is_a?(HiddenCommand) }.merge(map).keys.select { |n| meth == n[0, len] }.sort
unique_possibilities = possibilities.map { |k| map[k] || k }.uniq

if possibilities.include?(meth)
Expand Down
10 changes: 10 additions & 0 deletions spec/fixtures/script.thor
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ Linebreaks preserved
true
end

desc "potentially_ambiguous", "not really ambiguous because conflicting command is hidden"
def potentially_ambiguous
true
end

desc "potentially_ambiguous_but_hidden", "not considered for ambiguous check because it's hidden", hide: true
def potentially_ambiguous_but_hidden
false
end

private

def method_missing(meth, *args)
Expand Down
4 changes: 4 additions & 0 deletions spec/thor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ def self.exit_on_failure?
it "invokes an alias" do
expect(MyScript.start(%w(animal_pri))).to eq(MyScript.start(%w(zoo)))
end

it "invokes a command, even when there's a hidden command that makes invokation ambiguous" do
expect(MyScript.start(%w(potentially_))).to eq(MyScript.start(%w(potentially_ambiguous)))
end
end

context "when the user enters an ambiguous substring of a command" do
Expand Down