Skip to content

Commit 2ff4448

Browse files
committed
complete specs
1 parent e0ea989 commit 2ff4448

File tree

11 files changed

+193
-97
lines changed

11 files changed

+193
-97
lines changed

Gemfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ gem 'runfile'
88
gem 'runfile-tasks'
99
gem 'simplecov'
1010

11-
gem 'completely', path: '/vagrant/gems/completely'
11+
# === REMOVE BEFORE FLIGHT ===
12+
if Dir.exist? '/vagrant/gems/completely'
13+
gem 'completely', path: '/vagrant/gems/completely'
14+
else
15+
gem 'completely', git: "https://github.com/dannyben/completely.git"
16+
end
17+
# === REMOVE BEFORE FLIGHT ===
1218

1319
gemspec

lib/bashly/concerns/command_scopes.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ def all_full_names
1010
end
1111
end
1212

13-
# Returns only the names of the Commands
14-
def command_names
15-
commands.map &:name
16-
end
17-
1813
# Returns a full list of the Command names and aliases combined
1914
def command_aliases
2015
commands.map(&:aliases).flatten
2116
end
2217

18+
# Returns only the names of the Commands
19+
def command_names
20+
commands.map &:name
21+
end
22+
2323
# Returns a flat array containing all the commands in this tree.
2424
# This includes self + children + grandchildres + ...
2525
def deep_commands

spec/approvals/completions/advanced

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ say goodbye universe:
2525
- "$(git branch)"
2626
- "--color"
2727
- "--help"
28+
- "--path"
2829
- "--verbose"
2930
- "-c"
3031
- "-h"
3132
- "-v"
33+
say goodbye universe*--color: &1
34+
- green
35+
- red
36+
say goodbye universe*-c: *1
37+
say goodbye universe*--path:
38+
- "<file>"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
some command*--protocol: &1
3+
- ssh
4+
- sftp
5+
- https
6+
some command*-p: *1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
some command*--path: &1
3+
- "<file>"
4+
- README.md
5+
some command*-p: *1

spec/approvals/completions/script

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ _say_completions() {
1111
compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
1212

1313
case "$compline" in
14-
'goodbye universe'*) COMPREPLY=($(compgen -W "$(git branch) --color --help --verbose -c -h -v" -- "$cur")) ;;
14+
'goodbye universe'*'--color') COMPREPLY=($(compgen -W "green red" -- "$cur")) ;;
15+
'goodbye universe'*'--path') COMPREPLY=($(compgen -A file -- "$cur")) ;;
16+
'goodbye universe'*'-c') COMPREPLY=($(compgen -W "green red" -- "$cur")) ;;
17+
'goodbye universe'*) COMPREPLY=($(compgen -W "$(git branch) --color --help --path --verbose -c -h -v" -- "$cur")) ;;
1518
'hello world'*) COMPREPLY=($(compgen -A directory -A user -W "--force --help --verbose -h" -- "$cur")) ;;
1619
'goodbye'*) COMPREPLY=($(compgen -W "--help -h universe" -- "$cur")) ;;
1720
'hello'*) COMPREPLY=($(compgen -W "--help -h world" -- "$cur")) ;;

spec/bashly/concerns/completions_spec.rb renamed to spec/bashly/concerns/completions_command_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
require 'spec_helper'
22

33
describe Script::Command do
4-
let(:fixture) { :completions_simple }
4+
fixtures = load_fixture('script/commands')
55

6-
subject do
7-
options = load_fixture('script/commands')[fixture]
8-
described_class.new options
9-
end
6+
let(:fixture) { :completions_simple }
7+
subject { described_class.new fixtures[fixture] }
108

119
describe '#completion_data' do
1210
it "returns a data structure for completely" do
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper'
2+
3+
describe Script::Flag do
4+
fixtures = load_fixture('script/flags')
5+
6+
let(:fixture) { :basic_flag }
7+
let(:command) { "some command"}
8+
9+
subject { described_class.new fixtures[fixture] }
10+
11+
describe '#completion_data' do
12+
context "when the flag has allowed defined" do
13+
let(:fixture) { :completions_allowed }
14+
15+
it "returns a data structure for completely with the allowed list" do
16+
expect(subject.completion_data(command).to_yaml).to match_approval("completions/flag-allowed")
17+
end
18+
end
19+
20+
context "when the flag has completions defined" do
21+
let(:fixture) { :completions_completions }
22+
23+
it "returns a data structure for completely with the completions list" do
24+
expect(subject.completion_data(command).to_yaml).to match_approval("completions/flag-completions")
25+
end
26+
end
27+
28+
context "when the flag does not have allowed or completions" do
29+
it "returns an empty hash" do
30+
expect(subject.completion_data(command)).to eq({})
31+
end
32+
end
33+
end
34+
end

spec/bashly/script/command_spec.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
describe Script::Command do
44
let(:fixture) { :basic_command }
5-
6-
subject do
7-
options = load_fixture('script/commands')[fixture]
8-
described_class.new options
9-
end
5+
fixtures = load_fixture('script/commands')
6+
subject { described_class.new fixtures[fixture] }
107

118
describe '#action_name' do
129
context "when it is the root command" do
@@ -48,6 +45,14 @@
4845
end
4946
end
5047

48+
describe '#all_full_names' do
49+
let(:fixture) { :aliases }
50+
51+
it "returns an array of all full names including aliases" do
52+
expect(subject.commands.first.all_full_names).to eq ["apt download", "apt d", "apt pull"]
53+
end
54+
end
55+
5156
describe '#args' do
5257
it "returns an array of Argument objects" do
5358
expect(subject.args).to be_an Array
@@ -69,6 +74,14 @@
6974
end
7075
end
7176

77+
describe '#command_aliases' do
78+
let(:fixture) { :aliases }
79+
80+
it "returns an array of command aliases" do
81+
expect(subject.command_aliases).to eq ["download", "d", "pull", "upload", "u", "push", "update", "upgrade"]
82+
end
83+
end
84+
7285
describe '#command_names' do
7386
let(:fixture) { :docker }
7487

spec/fixtures/script/commands.yml

Lines changed: 94 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
:aliases:
2+
name: apt
3+
commands:
4+
- name: download
5+
alias: [d, pull]
6+
- name: upload
7+
alias: [u, push]
8+
- name: update
9+
alias: upgrade
10+
111
:basic_command:
212
name: get
313
alias: g
@@ -20,84 +30,6 @@
2030
required: true
2131
- name: target_folder
2232

23-
:git_status:
24-
name: status
25-
help: perform git status
26-
parents: [git]
27-
28-
:docker:
29-
name: docker
30-
help: run docker commands
31-
commands:
32-
- name: container
33-
commands:
34-
- name: run
35-
- name: stop
36-
- name: image
37-
38-
:docker_container_run:
39-
name: run
40-
help: perform docker container run
41-
parents: [docker, container]
42-
43-
:long_only_command:
44-
name: get
45-
help: get something from somewhere
46-
47-
:flags_only_command:
48-
name: status
49-
help: perform git status
50-
flags:
51-
- long: --force
52-
- long: --verbose
53-
parents: [git]
54-
55-
:helpless:
56-
name: helpless
57-
58-
:default_command:
59-
name: cli
60-
commands:
61-
- name: get
62-
default: true
63-
- name: post
64-
- name: put
65-
66-
:flag_hog:
67-
name: cli
68-
help: test when -h and -v are defined
69-
flags:
70-
- short: -h
71-
long: --hello
72-
- short: -v
73-
long: --vorld
74-
75-
:default_values:
76-
name: cli
77-
args:
78-
- name: files
79-
default: "*.jpg"
80-
flags:
81-
- short: -f
82-
long: --format
83-
arg: format
84-
default: png
85-
86-
:whitelist:
87-
name: cli
88-
args:
89-
- name: region
90-
allowed: [eu, us]
91-
- name: environment
92-
93-
flags:
94-
- long: --user
95-
arg: name
96-
allowed: [user, admin]
97-
98-
- long: --protocol
99-
arg: type
100-
10133
:catch_all:
10234
name: get
10335
help: get something from somewhere
@@ -145,6 +77,9 @@
14577
flags:
14678
- long: --color
14779
short: -c
80+
allowed: [green, red]
81+
- long: --path
82+
completions: [<file>]
14883
- long: --verbose
14984
short: -v
15085

@@ -163,12 +98,46 @@
16398
arg: name
16499
allowed: [get, post]
165100

101+
:custom_filename:
102+
name: run
103+
filename: ops/run_command.sh
104+
166105
:custom_header:
167106
name: check
168107

169-
:custom_filename:
108+
:default_command:
109+
name: cli
110+
commands:
111+
- name: get
112+
default: true
113+
- name: post
114+
- name: put
115+
116+
:default_values:
117+
name: cli
118+
args:
119+
- name: files
120+
default: "*.jpg"
121+
flags:
122+
- short: -f
123+
long: --format
124+
arg: format
125+
default: png
126+
127+
:docker:
128+
name: docker
129+
help: run docker commands
130+
commands:
131+
- name: container
132+
commands:
133+
- name: run
134+
- name: stop
135+
- name: image
136+
137+
:docker_container_run:
170138
name: run
171-
filename: ops/run_command.sh
139+
help: perform docker container run
140+
parents: [docker, container]
172141

173142
:filters_array:
174143
name: run
@@ -180,9 +149,54 @@
180149
name: run
181150
filters: docker_running
182151

152+
:flag_hog:
153+
name: cli
154+
help: test when -h and -v are defined
155+
flags:
156+
- short: -h
157+
long: --hello
158+
- short: -v
159+
long: --vorld
160+
161+
:flags_only_command:
162+
name: status
163+
help: perform git status
164+
flags:
165+
- long: --force
166+
- long: --verbose
167+
parents: [git]
168+
169+
:git_status:
170+
name: status
171+
help: perform git status
172+
parents: [git]
173+
174+
:helpless:
175+
name: helpless
176+
177+
:long_only_command:
178+
name: get
179+
help: get something from somewhere
180+
183181
:repeatable_arg:
184182
name: get
185183
args:
186184
- name: source
187185
- name: target
188186
repeatable: true
187+
188+
:whitelist:
189+
name: cli
190+
args:
191+
- name: region
192+
allowed: [eu, us]
193+
- name: environment
194+
195+
flags:
196+
- long: --user
197+
arg: name
198+
allowed: [user, admin]
199+
200+
- long: --protocol
201+
arg: type
202+

0 commit comments

Comments
 (0)