Skip to content

Commit 7f72d78

Browse files
committed
update specs
1 parent d557687 commit 7f72d78

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

lib/bashly/script/command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def commands
101101
end
102102

103103
# Returns a flat array containing all the commands in this tree.
104-
# This can children + grandchildres (recursive), and may include self
104+
# This includes children + grandchildren (recursive), and may include self
105105
def deep_commands(include_self: false)
106106
result = []
107107
result << self if include_self

lib/bashly/views/command/parse_requirements_case_repeatable.gtx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ args.each do |arg|
66
> {{ condition }} [[ -z ${args['{{ arg.name }}']+x} ]]; then
77
if arg.repeatable
88
> args['{{ arg.name }}']="$escaped"
9+
if arg.unique
10+
> unique_lookup["{{ arg.name }}:$escaped"]=1
11+
end
912
> shift
1013
if arg.unique
1114
> elif [[ -z "${unique_lookup["{{ arg.name }}:$escaped"]:-}" ]]; then

spec/bashly/script/command_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@
114114
expect(subject.deep_commands.map(&:full_name))
115115
.to eq ['docker container', 'docker container run', 'docker container stop', 'docker image']
116116
end
117+
118+
context 'when include_self is true' do
119+
it 'prepends the result with the command itself' do
120+
expect(subject.deep_commands(include_self: true).map(&:full_name))
121+
.to eq ['docker', 'docker container', 'docker container run', 'docker container stop', 'docker image']
122+
end
123+
end
117124
end
118125

119126
describe '#default_arguments' do
@@ -333,6 +340,46 @@
333340
end
334341
end
335342

343+
describe '#has_unique_args_or_flags?' do
344+
context 'when the command has any args that are unique' do
345+
let(:fixture) { :unique_args }
346+
347+
it 'returns true' do
348+
expect(subject.has_unique_args_or_flags?).to be true
349+
end
350+
end
351+
352+
context 'when the command has any flags that are unique' do
353+
let(:fixture) { :unique_flags }
354+
355+
it 'returns true' do
356+
expect(subject.has_unique_args_or_flags?).to be true
357+
end
358+
end
359+
360+
context 'when the command has any subcommands with unique args' do
361+
let(:fixture) { :unique_args_deep }
362+
363+
it 'returns true' do
364+
expect(subject.has_unique_args_or_flags?).to be true
365+
end
366+
end
367+
368+
context 'when the command has any subcommands with unique flags' do
369+
let(:fixture) { :unique_flags_deep }
370+
371+
it 'returns true' do
372+
expect(subject.has_unique_args_or_flags?).to be true
373+
end
374+
end
375+
376+
context 'otherwise' do
377+
it 'returns false' do
378+
expect(subject.has_unique_args_or_flags?).to be false
379+
end
380+
end
381+
end
382+
336383
describe '#load_user_file' do
337384
before do
338385
FileUtils.mkdir_p 'spec/tmp/src'

spec/fixtures/script/commands.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,40 @@
398398
- name: target
399399
repeatable: true
400400

401+
:unique_args:
402+
name: get
403+
args:
404+
- name: file
405+
repeatable: true
406+
unique: true
407+
408+
:unique_flags:
409+
name: get
410+
flags:
411+
- short: --file
412+
arg: path
413+
repeatable: true
414+
unique: true
415+
416+
:unique_args_deep:
417+
name: ftp
418+
commands:
419+
- name: upload
420+
args:
421+
- name: file
422+
repeatable: true
423+
unique: true
424+
425+
:unique_flags_deep:
426+
name: ftp
427+
commands:
428+
- name: upload
429+
flags:
430+
- long: --file
431+
arg: path
432+
repeatable: true
433+
unique: true
434+
401435
:whitelist:
402436
name: cli
403437
args:

0 commit comments

Comments
 (0)