Skip to content

Commit e36b9e3

Browse files
committed
Merge branch 'master' into add/yaml-compose
2 parents bc71787 + 9f3ff81 commit e36b9e3

File tree

10 files changed

+100
-12
lines changed

10 files changed

+100
-12
lines changed

lib/bashly/script/argument.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ class Argument < Base
44
def usage_string
55
required ? name.upcase : "[#{name.upcase}]"
66
end
7+
8+
def verify
9+
raise ConfigurationError, "Argument must have a name" unless name
10+
end
711
end
812
end
913
end

lib/bashly/script/command.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def user_lib
216216
# definition.
217217
def verify
218218
verify_commands if commands.any?
219+
raise ConfigurationError, "Command must have a name" unless name
219220
end
220221

221222
# Returns an array of all the args with a whitelist

lib/bashly/script/environment_variable.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ def usage_string(extended: false)
66
result << strings[:required] if required and extended
77
result.join " "
88
end
9+
10+
def verify
11+
raise ConfigurationError, "EnvironmentVariable must have a name" unless name
12+
end
913
end
1014
end
1115
end

lib/bashly/script/flag.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def usage_string(extended: false)
2121
result << strings[:required] if required and extended
2222
result.join " "
2323
end
24+
25+
def verify
26+
raise ConfigurationError, "Flag must have a long and/or short property" unless short or long
27+
end
28+
2429
end
2530
end
2631
end

spec/bashly/script/argument_spec.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
require 'spec_helper'
22

33
describe Script::Argument do
4-
let(:options) { {"name" => "file"} }
5-
subject { described_class.new options }
4+
let(:fixture) { :basic_argument }
5+
6+
subject do
7+
options = load_fixture('script/arguments')[fixture]
8+
described_class.new options
9+
end
610

711
describe '#usage_string' do
812
it "returns a string suitable to be used as a usage pattern" do
913
expect(subject.usage_string).to eq "[FILE]"
1014
end
1115

1216
context "when the argument is required" do
13-
let(:options) { {"name" => "file", "required" => true} }
17+
let(:fixture) { :required }
18+
1419
it "returns a string suitable to be used as a usage pattern" do
1520
expect(subject.usage_string).to eq "FILE"
1621
end
1722
end
1823
end
1924

25+
describe '#verify' do
26+
context "when the argument has no name" do
27+
let(:fixture) { :invalid_without_name }
28+
29+
it "raises an error" do
30+
expect { subject.verify }.to raise_error(ConfigurationError, /must have a name/)
31+
end
32+
end
33+
end
34+
2035
end

spec/bashly/script/command_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,14 @@
410410
expect { subject.verify }.to raise_error(ConfigurationError, /cannot be at the same level/)
411411
end
412412
end
413+
414+
context "when the command has no name" do
415+
let(:fixture) { :invalid_without_name }
416+
417+
it "raises an error" do
418+
expect { subject.verify }.to raise_error(ConfigurationError, /must have a name/)
419+
end
420+
end
413421
end
414422

415423
describe '#whitelisted_args' do
@@ -430,5 +438,4 @@
430438
end
431439
end
432440

433-
434441
end

spec/bashly/script/flag_spec.rb

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

33
describe Script::Flag do
4-
let(:options) { {"long" => "--help", "short" => "-h", "help" => "show this help"} }
5-
subject { described_class.new options }
4+
let(:fixture) { :basic_flag }
5+
6+
subject do
7+
options = load_fixture('script/flags')[fixture]
8+
described_class.new options
9+
end
610

711
describe '#aliases' do
812
context "with long and short options" do
@@ -12,14 +16,16 @@
1216
end
1317

1418
context "with long option only" do
15-
let(:options) { {"long" => "--long"} }
19+
let(:fixture) { :long_only }
20+
1621
it "returns an array with the long value" do
1722
expect(subject.aliases).to eq ["--long"]
1823
end
1924
end
2025

2126
context "with short option only" do
22-
let(:options) { {"short" => "-s"} }
27+
let(:fixture) { :short_only }
28+
2329
it "returns an array with the short value" do
2430
expect(subject.aliases).to eq ["-s"]
2531
end
@@ -34,14 +40,16 @@
3440
end
3541

3642
context "with long option only" do
37-
let(:options) { {"long" => "-l"} }
43+
let(:fixture) { :long_only }
44+
3845
it "returns the long option" do
39-
expect(subject.name).to eq "-l"
46+
expect(subject.name).to eq "--long"
4047
end
4148
end
4249

4350
context "with short option only" do
44-
let(:options) { {"short" => "-s"} }
51+
let(:fixture) { :short_only }
52+
4553
it "returns the short option" do
4654
expect(subject.name).to eq "-s"
4755
end
@@ -61,7 +69,8 @@
6169
end
6270

6371
context "when the flag is required" do
64-
let(:options) { {"long" => "--mandatory", "required" => true} }
72+
let(:fixture) { :required }
73+
6574
it "appends (required) to the usage string" do
6675
expect(subject.usage_string extended: true).to eq "#{subject.usage_string} (required)"
6776
end
@@ -70,4 +79,15 @@
7079
end
7180
end
7281

82+
describe '#verify' do
83+
context "when the flag has no short or long" do
84+
let(:fixture) { :invalid_without_name }
85+
86+
it "raises an error" do
87+
expect { subject.verify }.to raise_error(ConfigurationError, /must have a long and\/or short property/)
88+
end
89+
end
90+
end
91+
92+
7393
end

spec/fixtures/script/arguments.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:basic_argument:
2+
name: file
3+
4+
:required:
5+
name: file
6+
required: true
7+
8+
:invalid_without_name:
9+
help: invalid since there is no name

spec/fixtures/script/commands.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@
7171
flags:
7272
- long: --force
7373

74+
:invalid_without_name:
75+
help: invalid since there is no name
76+
7477
:default_command:
78+
name: cli
7579
commands:
7680
- name: get
7781
default: true
@@ -88,6 +92,7 @@
8892
long: --vorld
8993

9094
:default_values:
95+
name: cli
9196
args:
9297
- name: files
9398
default: "*.jpg"
@@ -98,6 +103,7 @@
98103
default: png
99104

100105
:whitelist:
106+
name: cli
101107
args:
102108
- name: region
103109
allowed: [eu, us]

spec/fixtures/script/flags.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
:basic_flag:
2+
long: --help
3+
short: -h
4+
help: show this help
5+
6+
:long_only:
7+
long: --long
8+
9+
:short_only:
10+
short: -s
11+
12+
:required:
13+
long: --mandatory
14+
required: true
15+
16+
:invalid_without_name:
17+
help: invalid since there is no name

0 commit comments

Comments
 (0)