Skip to content

Commit 0eaec10

Browse files
authored
Merge pull request #911 from deivid-rodriguez/dont-suggest-hidden-commands
Hidden commands should not make an invocation ambiguous
2 parents f431ef0 + 59a764a commit 0eaec10

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/thor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def normalize_command_name(meth) #:nodoc:
625625
# alias name.
626626
def find_command_possibilities(meth)
627627
len = meth.to_s.length
628-
possibilities = all_commands.merge(map).keys.select { |n| meth == n[0, len] }.sort
628+
possibilities = all_commands.reject {|k, v| v.is_a?(HiddenCommand) }.merge(map).keys.select { |n| meth == n[0, len] }.sort
629629
unique_possibilities = possibilities.map { |k| map[k] || k }.uniq
630630

631631
if possibilities.include?(meth)

spec/fixtures/script.thor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ Linebreaks preserved
129129
true
130130
end
131131

132+
desc "potentially_ambiguous", "not really ambiguous because conflicting command is hidden"
133+
def potentially_ambiguous
134+
true
135+
end
136+
137+
desc "potentially_ambiguous_but_hidden", "not considered for ambiguous check because it's hidden", hide: true
138+
def potentially_ambiguous_but_hidden
139+
false
140+
end
141+
132142
private
133143

134144
def method_missing(meth, *args)

spec/thor_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@ def self.exit_on_failure?
522522
it "invokes an alias" do
523523
expect(MyScript.start(%w(animal_pri))).to eq(MyScript.start(%w(zoo)))
524524
end
525+
526+
it "invokes a command, even when there's a hidden command that makes invokation ambiguous" do
527+
expect(MyScript.start(%w(potentially_))).to eq(MyScript.start(%w(potentially_ambiguous)))
528+
end
525529
end
526530

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

0 commit comments

Comments
 (0)