Skip to content

Commit 2ce5d2b

Browse files
committed
fix implementation and add specs
1 parent 567d194 commit 2ce5d2b

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

lib/bashly/concerns/completions.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,19 @@ def completion_flag_names
3131
flags.map(&:name) + flags.map(&:short)
3232
end
3333

34-
def completion_flag_whitelist
35-
flags.map(&:allowed).flatten
34+
def completion_allowed_args
35+
flags.map(&:allowed).flatten + args.map(&:allowed).flatten
3636
end
3737

3838
def completion_words(with_version: false)
3939
trivial_flags = %w[--help -h]
4040
trivial_flags += %w[--version -v] if with_version
4141
all = (
4242
command_names + trivial_flags +
43-
completion_flag_names +
44-
completion_flag_whitelist
43+
completion_flag_names + completion_allowed_args
4544
)
4645

4746
all += completions if completions
48-
all += allowed if allowed
4947
all.compact.uniq.sort
5048
end
5149

spec/approvals/completions/whitelist

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
download:
3+
- "--help"
4+
- "--method"
5+
- "--role"
6+
- "--version"
7+
- "-h"
8+
- "-v"
9+
- '22'
10+
- '3000'
11+
- '80'
12+
- admin
13+
- get
14+
- https
15+
- post
16+
- ssh
17+
- user

spec/bashly/concerns/completions_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,15 @@
3838
end
3939
end
4040
end
41+
42+
context "with a command that uses whitelist args" do
43+
let(:fixture) { :completions_whitelist }
44+
45+
describe '#completion_data' do
46+
it "returns a data structure that includes thw whitelist" do
47+
expect(subject.completion_data.to_yaml)
48+
.to match_approval("completions/whitelist")
49+
end
50+
end
51+
end
4152
end

spec/fixtures/models/commands.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,20 @@
161161
- long: --verbose
162162
short: -v
163163

164+
:completions_whitelist:
165+
name: download
166+
args:
167+
- name: protocol
168+
allowed: [https, ssh]
169+
- name: port
170+
allowed: ["80", "22", "3000"]
171+
flags:
172+
- long: --role
173+
arg: name
174+
allowed: [user, admin]
175+
- long: --method
176+
arg: name
177+
allowed: [get, post]
178+
164179
:custom_header:
165180
name: check

0 commit comments

Comments
 (0)