Skip to content

Commit 6769570

Browse files
committed
avoid offering wildcard aliases as completions
1 parent 88699ab commit 6769570

5 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎lib/bashly/script/introspection/commands.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def command_names
4141
commands.map(&:name)
4242
end
4343

44+
# Returns command names and aliases that can be offered as completions
45+
def completion_aliases
46+
public_commands.flat_map(&:aliases).reject { |name| name.end_with? '*' }
47+
end
48+
4449
# Returns an array of the Commands
4550
def commands
4651
return [] unless options['commands']
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
if public_command_aliases.any?
2-
> completion_candidates "$completion_current" {{ public_command_aliases.join ' ' }}
1+
if completion_aliases.any?
2+
> completion_candidates "$completion_current" {{ completion_aliases.join ' ' }}
33
end

‎spec/bashly/script/introspection/commands_spec.rb‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
end
5353
end
5454

55+
describe '#completion_aliases' do
56+
let(:fixture) { :completion_aliases }
57+
58+
it 'returns public command aliases without wildcard aliases' do
59+
expect(subject.completion_aliases).to eq %w[download d upload]
60+
end
61+
end
62+
5563
describe '#commands' do
5664
let(:fixture) { :docker }
5765

‎spec/fixtures/completions/core/src/bashly.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ commands:
3737
alias: down
3838
help: Stop a server
3939
- name: status
40+
alias: stat*
4041
help: Show server status
4142

4243
- name: config

‎spec/fixtures/script/commands.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
- name: update
99
alias: upgrade
1010

11+
:completion_aliases:
12+
name: cli
13+
commands:
14+
- name: download
15+
alias: [d, down*]
16+
- name: upload
17+
- name: internal
18+
private: true
19+
1120
:basic_command:
1221
name: get
1322
alias: g

0 commit comments

Comments
 (0)