convoy 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.irbrc +3 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +705 -0
- data/Rakefile +1 -0
- data/convoy.gemspec +24 -0
- data/examples/.my_apprc +24 -0
- data/examples/basic +10 -0
- data/examples/basic_config_file +16 -0
- data/examples/basic_conflicts +17 -0
- data/examples/basic_depends_on +25 -0
- data/examples/basic_flags +15 -0
- data/examples/basic_options +14 -0
- data/examples/basic_options_multi +15 -0
- data/examples/basic_require_arguments +17 -0
- data/examples/basic_texts +21 -0
- data/examples/basic_validations +21 -0
- data/examples/basic_with_everything +30 -0
- data/examples/commands/example_command.rb +13 -0
- data/examples/suite_complex +65 -0
- data/examples/suite_simple +19 -0
- data/examples/suite_with_sub_commands +94 -0
- data/lib/convoy.rb +83 -0
- data/lib/convoy/action_command/base.rb +85 -0
- data/lib/convoy/action_command/escort_utility_command.rb +53 -0
- data/lib/convoy/app.rb +127 -0
- data/lib/convoy/arguments.rb +20 -0
- data/lib/convoy/auto_options.rb +71 -0
- data/lib/convoy/error/error.rb +33 -0
- data/lib/convoy/formatter/command.rb +87 -0
- data/lib/convoy/formatter/commands.rb +37 -0
- data/lib/convoy/formatter/cursor_position.rb +29 -0
- data/lib/convoy/formatter/default_help_formatter.rb +117 -0
- data/lib/convoy/formatter/global_command.rb +17 -0
- data/lib/convoy/formatter/option.rb +152 -0
- data/lib/convoy/formatter/options.rb +28 -0
- data/lib/convoy/formatter/shell_command_executor.rb +49 -0
- data/lib/convoy/formatter/stream_output_formatter.rb +88 -0
- data/lib/convoy/formatter/string_grid.rb +108 -0
- data/lib/convoy/formatter/string_splitter.rb +50 -0
- data/lib/convoy/formatter/terminal.rb +30 -0
- data/lib/convoy/global_pre_parser.rb +43 -0
- data/lib/convoy/logger.rb +75 -0
- data/lib/convoy/option_dependency_validator.rb +82 -0
- data/lib/convoy/option_parser.rb +155 -0
- data/lib/convoy/setup/configuration/generator.rb +75 -0
- data/lib/convoy/setup/configuration/instance.rb +34 -0
- data/lib/convoy/setup/configuration/loader.rb +43 -0
- data/lib/convoy/setup/configuration/locator/base.rb +19 -0
- data/lib/convoy/setup/configuration/locator/chaining.rb +29 -0
- data/lib/convoy/setup/configuration/locator/descending_to_home.rb +23 -0
- data/lib/convoy/setup/configuration/locator/executing_script_directory.rb +15 -0
- data/lib/convoy/setup/configuration/locator/specified_directory.rb +21 -0
- data/lib/convoy/setup/configuration/merge_tool.rb +38 -0
- data/lib/convoy/setup/configuration/reader.rb +36 -0
- data/lib/convoy/setup/configuration/writer.rb +46 -0
- data/lib/convoy/setup/dsl/action.rb +17 -0
- data/lib/convoy/setup/dsl/command.rb +67 -0
- data/lib/convoy/setup/dsl/config_file.rb +13 -0
- data/lib/convoy/setup/dsl/global.rb +29 -0
- data/lib/convoy/setup/dsl/options.rb +81 -0
- data/lib/convoy/setup_accessor.rb +206 -0
- data/lib/convoy/trollop.rb +861 -0
- data/lib/convoy/utils.rb +21 -0
- data/lib/convoy/validator.rb +45 -0
- data/spec/integration/basic_config_file_spec.rb +126 -0
- data/spec/integration/basic_conflicts_spec.rb +47 -0
- data/spec/integration/basic_depends_on_spec.rb +275 -0
- data/spec/integration/basic_options_spec.rb +41 -0
- data/spec/integration/basic_options_with_multi_spec.rb +30 -0
- data/spec/integration/basic_spec.rb +38 -0
- data/spec/integration/basic_validations_spec.rb +77 -0
- data/spec/integration/basic_with_arguments_spec.rb +35 -0
- data/spec/integration/basic_with_text_fields_spec.rb +21 -0
- data/spec/integration/suite_simple_spec.rb +45 -0
- data/spec/integration/suite_sub_command_spec.rb +51 -0
- data/spec/lib/convoy/action_command/base_spec.rb +200 -0
- data/spec/lib/convoy/formatter/command_spec.rb +238 -0
- data/spec/lib/convoy/formatter/global_command_spec.rb +50 -0
- data/spec/lib/convoy/formatter/option_spec.rb +300 -0
- data/spec/lib/convoy/formatter/shell_command_executor_spec.rb +59 -0
- data/spec/lib/convoy/formatter/stream_output_formatter_spec.rb +214 -0
- data/spec/lib/convoy/formatter/string_grid_spec.rb +59 -0
- data/spec/lib/convoy/formatter/string_splitter_spec.rb +50 -0
- data/spec/lib/convoy/formatter/terminal_spec.rb +19 -0
- data/spec/lib/convoy/setup/configuration/generator_spec.rb +101 -0
- data/spec/lib/convoy/setup/configuration/loader_spec.rb +79 -0
- data/spec/lib/convoy/setup/configuration/locator/chaining_spec.rb +81 -0
- data/spec/lib/convoy/setup/configuration/locator/descending_to_home_spec.rb +57 -0
- data/spec/lib/convoy/setup/configuration/locator/executing_script_directory_spec.rb +29 -0
- data/spec/lib/convoy/setup/configuration/locator/specified_directory_spec.rb +33 -0
- data/spec/lib/convoy/setup/configuration/merge_tool_spec.rb +41 -0
- data/spec/lib/convoy/setup/configuration/reader_spec.rb +41 -0
- data/spec/lib/convoy/setup/configuration/writer_spec.rb +75 -0
- data/spec/lib/convoy/setup_accessor_spec.rb +226 -0
- data/spec/lib/convoy/utils_spec.rb +30 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/integration_helpers.rb +2 -0
- data/spec/support/matchers/execute_action_for_command_matcher.rb +21 -0
- data/spec/support/matchers/execute_action_with_arguments_matcher.rb +25 -0
- data/spec/support/matchers/execute_action_with_options_matcher.rb +29 -0
- data/spec/support/matchers/exit_with_code_matcher.rb +29 -0
- data/spec/support/shared_contexts/integration_setup.rb +34 -0
- metadata +292 -0
@@ -0,0 +1,238 @@
|
|
1
|
+
describe Convoy::Formatter::Command do
|
2
|
+
let(:command) { Convoy::Formatter::Command.new(name, setup, context) }
|
3
|
+
let(:setup) { Convoy::SetupAccessor.new(app_configuration) }
|
4
|
+
let(:context) { [] }
|
5
|
+
let(:name) { :command1 }
|
6
|
+
let(:command_alias) { :c1 }
|
7
|
+
let(:aliases) { [command_alias] }
|
8
|
+
let(:summary) { 'command summary' }
|
9
|
+
let(:description) { 'command description' }
|
10
|
+
|
11
|
+
let(:app_configuration) do
|
12
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
13
|
+
app.command name, :aliases => aliases do |command|
|
14
|
+
command.summary summary
|
15
|
+
command.description description
|
16
|
+
|
17
|
+
command.action do |options, arguments|
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#description" do
|
24
|
+
subject { command.description }
|
25
|
+
|
26
|
+
context "when no description" do
|
27
|
+
let(:description) { nil }
|
28
|
+
it { subject.should == '' }
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when has description" do
|
32
|
+
let(:description) { 'command description' }
|
33
|
+
it { subject.should == description }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#summary" do
|
38
|
+
subject { command.summary }
|
39
|
+
|
40
|
+
context "when no summary" do
|
41
|
+
let(:summary) { nil }
|
42
|
+
it { subject.should == '' }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when has summary" do
|
46
|
+
let(:summary) { 'command summary' }
|
47
|
+
it { subject.should == summary }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "#has_aliases?" do
|
52
|
+
subject { command.has_aliases? }
|
53
|
+
|
54
|
+
context "when no aliases" do
|
55
|
+
let(:aliases) { [] }
|
56
|
+
it { subject.should be_false }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when has an alias" do
|
60
|
+
let(:aliases) { [command_alias] }
|
61
|
+
it { subject.should be_true }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "#aliases" do
|
66
|
+
subject { command.aliases }
|
67
|
+
|
68
|
+
context "when no aliases" do
|
69
|
+
let(:aliases) { [] }
|
70
|
+
it { subject.should == [] }
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when has an alias" do
|
74
|
+
let(:aliases) { [command_alias] }
|
75
|
+
it { subject.first.should == command_alias }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "#outline" do
|
80
|
+
subject { command.outline }
|
81
|
+
|
82
|
+
context "when no summary or description" do
|
83
|
+
let(:summary) { nil }
|
84
|
+
let(:description) { nil }
|
85
|
+
it { subject.should == '' }
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when no summary" do
|
89
|
+
let(:summary) { nil }
|
90
|
+
let(:description) { 'desc 1' }
|
91
|
+
it { subject.should == 'desc 1' }
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when no description" do
|
95
|
+
let(:summary) { 'summary 1' }
|
96
|
+
let(:description) { nil }
|
97
|
+
it { subject.should == 'summary 1' }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "#aliases" do
|
102
|
+
subject { command.name_with_aliases }
|
103
|
+
|
104
|
+
context "when no aliases" do
|
105
|
+
let(:aliases) { [] }
|
106
|
+
it { subject.should == "command1" }
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when has an alias" do
|
110
|
+
let(:aliases) { [command_alias] }
|
111
|
+
it { subject.should == "command1, #{command_alias}" }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "#script_name" do
|
116
|
+
subject { command.script_name }
|
117
|
+
|
118
|
+
context "when context is global" do
|
119
|
+
let(:context) { [] }
|
120
|
+
it { subject.split(" ").count.should == 1 }
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when context is not global" do
|
124
|
+
let(:context) { [:hello] }
|
125
|
+
it { subject.split(" ").count.should == 2 }
|
126
|
+
it { subject.split(" ").include?('hello').should be_true }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "#child_commands" do
|
131
|
+
subject { command.child_commands }
|
132
|
+
|
133
|
+
context "when no child commands" do
|
134
|
+
let(:app_configuration) do
|
135
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
136
|
+
app.action do |options, arguments|
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
it { subject.should be_empty }
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when has child commands" do
|
144
|
+
it { subject.should_not be_empty }
|
145
|
+
it { subject.count.should == 1 }
|
146
|
+
it { subject.first.should == :command1 }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "#has_child_commands?" do
|
151
|
+
subject { command.has_child_commands? }
|
152
|
+
|
153
|
+
context "when no child commands" do
|
154
|
+
let(:app_configuration) do
|
155
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
156
|
+
app.action do |options, arguments|
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
it { subject.should be_false }
|
161
|
+
end
|
162
|
+
|
163
|
+
context "when has child commands" do
|
164
|
+
it { subject.should be_true }
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "#requires_arguments?" do
|
169
|
+
subject { command.requires_arguments? }
|
170
|
+
|
171
|
+
context "when arguments not required" do
|
172
|
+
it { subject.should be_false }
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when arguments are required" do
|
176
|
+
let(:app_configuration) do
|
177
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
178
|
+
app.requires_arguments
|
179
|
+
app.action do |options, arguments|
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
it { subject.should be_true }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "#usage" do
|
188
|
+
subject { command.usage }
|
189
|
+
|
190
|
+
before do
|
191
|
+
$0 = 'hello'
|
192
|
+
end
|
193
|
+
|
194
|
+
context "when global command with no children" do
|
195
|
+
let(:app_configuration) do
|
196
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
197
|
+
app.action do |options, arguments|
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
it { subject.split(" ").first.should == 'hello' }
|
202
|
+
it { subject.split(" ")[1].should == '[options]' }
|
203
|
+
it { subject.split(" ")[2].should == '[arguments]' }
|
204
|
+
end
|
205
|
+
|
206
|
+
context "when global command with children" do
|
207
|
+
it { subject.split(" ").first.should == 'hello' }
|
208
|
+
it { subject.split(" ")[1].should == '[options]' }
|
209
|
+
it { subject.split(" ")[2].should == 'command' }
|
210
|
+
it { subject.split(" ")[3].should == '[command_options]' }
|
211
|
+
it { subject.split(" ")[4].should == '[arguments]' }
|
212
|
+
end
|
213
|
+
|
214
|
+
context "when global command and requires arguments" do
|
215
|
+
let(:app_configuration) do
|
216
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
217
|
+
app.requires_arguments
|
218
|
+
app.action do |options, arguments|
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
it { subject.split(" ").last.should == 'arguments' }
|
223
|
+
end
|
224
|
+
|
225
|
+
context "when does not require arguments" do
|
226
|
+
it { subject.split(" ").last.should == '[arguments]' }
|
227
|
+
end
|
228
|
+
|
229
|
+
context "when child command context with no children of its own" do
|
230
|
+
let(:context) { [:command1] }
|
231
|
+
it { subject.split(" ").first.should == 'hello' }
|
232
|
+
it { subject.split(" ")[1].should == '[options]' }
|
233
|
+
it { subject.split(" ")[2].should == 'command1' }
|
234
|
+
it { subject.split(" ")[3].should == '[command1_options]' }
|
235
|
+
it { subject.split(" ")[4].should == '[arguments]' }
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
describe Convoy::Formatter::GlobalCommand do
|
2
|
+
let(:command) { Convoy::Formatter::GlobalCommand.new(setup) }
|
3
|
+
let(:setup) { Convoy::SetupAccessor.new(app_configuration) }
|
4
|
+
let(:context) { [] }
|
5
|
+
let(:name) { :command1 }
|
6
|
+
let(:command_alias) { :c1 }
|
7
|
+
let(:aliases) { [command_alias] }
|
8
|
+
let(:summary) { 'app summary' }
|
9
|
+
let(:description) { 'app description' }
|
10
|
+
|
11
|
+
let(:app_configuration) do
|
12
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
13
|
+
app.summary summary
|
14
|
+
app.description description
|
15
|
+
|
16
|
+
app.command name, :aliases => aliases do |command|
|
17
|
+
command.action do |options, arguments|
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#description" do
|
24
|
+
subject { command.description }
|
25
|
+
|
26
|
+
context "when no description" do
|
27
|
+
let(:description) { nil }
|
28
|
+
it { subject.should == '' }
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when has description" do
|
32
|
+
let(:description) { 'app description' }
|
33
|
+
it { subject.should == description }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#summary" do
|
38
|
+
subject { command.summary }
|
39
|
+
|
40
|
+
context "when no summary" do
|
41
|
+
let(:summary) { nil }
|
42
|
+
it { subject.should == '' }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when has summary" do
|
46
|
+
let(:summary) { 'app summary' }
|
47
|
+
it { subject.should == summary }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
describe Convoy::Formatter::Option do
|
2
|
+
let(:option) { Convoy::Formatter::Option.new(name, details, setup, context) }
|
3
|
+
let(:setup) { Convoy::SetupAccessor.new(app_configuration) }
|
4
|
+
let(:context) { [] }
|
5
|
+
let(:name) { 'option1' }
|
6
|
+
let(:details) do
|
7
|
+
{:short => short, :long => "option1", :type => type, :default => default, :desc => desc, :multi => false}
|
8
|
+
end
|
9
|
+
let(:short) { :none }
|
10
|
+
let(:type) { :string }
|
11
|
+
let(:default) { 'foo' }
|
12
|
+
let(:desc) { 'Option 1' }
|
13
|
+
let(:app_configuration) do
|
14
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#usage" do
|
19
|
+
subject { option.usage }
|
20
|
+
|
21
|
+
context "when option is a flag" do
|
22
|
+
let(:type) { :flag }
|
23
|
+
|
24
|
+
context "and it has a default value of 'true'" do
|
25
|
+
let(:default) { true }
|
26
|
+
it { subject.should == '--option1, --no-option1' }
|
27
|
+
end
|
28
|
+
|
29
|
+
context "and its default value is 'false'" do
|
30
|
+
let(:default) { false }
|
31
|
+
it { subject.should == '--option1' }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when option is not a flag' do
|
36
|
+
let(:type) { :string }
|
37
|
+
|
38
|
+
context "and it has no short specification" do
|
39
|
+
let(:short) { :none }
|
40
|
+
it { subject.should == '--option1 <s>' }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "and it has a short specification" do
|
44
|
+
let(:short) { 'o' }
|
45
|
+
it { subject.should == '--option1 -o <s>' }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#description" do
|
51
|
+
subject { option.description }
|
52
|
+
|
53
|
+
context "when no description" do
|
54
|
+
let(:desc) { nil }
|
55
|
+
context "and has no default value" do
|
56
|
+
let(:default) { nil }
|
57
|
+
it { subject.should == '' }
|
58
|
+
end
|
59
|
+
|
60
|
+
context "and has a default value" do
|
61
|
+
let(:default) { "blah" }
|
62
|
+
it { subject.should == '(default: blah)' }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when has description" do
|
67
|
+
context "and description end with dot" do
|
68
|
+
let(:desc) { "Option 1." }
|
69
|
+
|
70
|
+
context "and has no default value" do
|
71
|
+
let(:default) { nil }
|
72
|
+
it { subject.should == 'Option 1.' }
|
73
|
+
end
|
74
|
+
|
75
|
+
context "and has a default value" do
|
76
|
+
let(:default) { "blah" }
|
77
|
+
it { subject.should == 'Option 1. (Default: blah)' }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "and description does not end with dot" do
|
82
|
+
let(:desc) { "Option 1" }
|
83
|
+
|
84
|
+
context "and has no default value" do
|
85
|
+
let(:default) { nil }
|
86
|
+
it { subject.should == 'Option 1' }
|
87
|
+
end
|
88
|
+
|
89
|
+
context "and has a default value" do
|
90
|
+
let(:default) { "blah" }
|
91
|
+
it { subject.should == 'Option 1 (default: blah)' }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#has_conflicts?" do
|
98
|
+
subject { option.has_conflicts? }
|
99
|
+
context "when no conflicts defined" do
|
100
|
+
let(:app_configuration) do
|
101
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
102
|
+
app.options do |opts|
|
103
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
104
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
105
|
+
end
|
106
|
+
|
107
|
+
app.action do |options, arguments|
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
it { subject.should be_false }
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when conflict is defined" do
|
115
|
+
let(:app_configuration) do
|
116
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
117
|
+
app.options do |opts|
|
118
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :conflicts_with => :option2
|
119
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
120
|
+
end
|
121
|
+
|
122
|
+
app.action do |options, arguments|
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
it { subject.should be_true }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#has_dependencies?" do
|
131
|
+
subject { option.has_dependencies? }
|
132
|
+
context "when no dependencies defined" do
|
133
|
+
let(:app_configuration) do
|
134
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
135
|
+
app.options do |opts|
|
136
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
137
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
138
|
+
end
|
139
|
+
|
140
|
+
app.action do |options, arguments|
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
it { subject.should be_false }
|
145
|
+
end
|
146
|
+
|
147
|
+
context "when dependency is defined" do
|
148
|
+
let(:app_configuration) do
|
149
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
150
|
+
app.options do |opts|
|
151
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :depends_on => :option2
|
152
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
153
|
+
end
|
154
|
+
|
155
|
+
app.action do |options, arguments|
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
it { subject.should be_true }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "#has_validations?" do
|
164
|
+
subject { option.has_validations? }
|
165
|
+
context "when no validations defined" do
|
166
|
+
let(:app_configuration) do
|
167
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
168
|
+
app.options do |opts|
|
169
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
170
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
171
|
+
end
|
172
|
+
|
173
|
+
app.action do |options, arguments|
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
it { subject.should be_false }
|
178
|
+
end
|
179
|
+
|
180
|
+
context "when validations is defined" do
|
181
|
+
let(:app_configuration) do
|
182
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
183
|
+
app.options do |opts|
|
184
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
185
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
186
|
+
|
187
|
+
opts.validate(:option1, "must be 'foo'") { |option| option == 'foo' }
|
188
|
+
end
|
189
|
+
|
190
|
+
app.action do |options, arguments|
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
it { subject.should be_true }
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "#conflicts" do
|
199
|
+
subject { option.conflicts }
|
200
|
+
context "when no conflicts defined" do
|
201
|
+
let(:app_configuration) do
|
202
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
203
|
+
app.options do |opts|
|
204
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
205
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
206
|
+
end
|
207
|
+
|
208
|
+
app.action do |options, arguments|
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
it { subject.should == '' }
|
213
|
+
end
|
214
|
+
|
215
|
+
context "when conflict is defined" do
|
216
|
+
let(:app_configuration) do
|
217
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
218
|
+
app.options do |opts|
|
219
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :conflicts_with => [:option2, :option3]
|
220
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
221
|
+
opts.opt :option3, "Option3", :short => :none, :long => '--option3', :type => :string
|
222
|
+
end
|
223
|
+
|
224
|
+
app.action do |options, arguments|
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
it { subject.should == 'conflicts with: --option2, --option3' }
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe "#dependencies" do
|
233
|
+
subject { option.dependencies }
|
234
|
+
context "when no dependencies defined" do
|
235
|
+
let(:app_configuration) do
|
236
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
237
|
+
app.options do |opts|
|
238
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
239
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
240
|
+
end
|
241
|
+
|
242
|
+
app.action do |options, arguments|
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
it { subject.should == '' }
|
247
|
+
end
|
248
|
+
|
249
|
+
context "when dependency is defined" do
|
250
|
+
let(:app_configuration) do
|
251
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
252
|
+
app.options do |opts|
|
253
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :depends_on => :option2
|
254
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
255
|
+
end
|
256
|
+
|
257
|
+
app.action do |options, arguments|
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
it { subject.should == 'depends on: --option2' }
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "#validations" do
|
266
|
+
subject { option.validations }
|
267
|
+
context "when no validations defined" do
|
268
|
+
let(:app_configuration) do
|
269
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
270
|
+
app.options do |opts|
|
271
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
272
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
273
|
+
end
|
274
|
+
|
275
|
+
app.action do |options, arguments|
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
it { subject.should == [] }
|
280
|
+
end
|
281
|
+
|
282
|
+
context "when validations is defined" do
|
283
|
+
let(:app_configuration) do
|
284
|
+
Convoy::Setup::Dsl::Global.new do |app|
|
285
|
+
app.options do |opts|
|
286
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
287
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
|
288
|
+
|
289
|
+
opts.validate(:option1, "must be 'foo'") { |option| option == 'foo' }
|
290
|
+
opts.validate(:option1, "must not be 'bar'") { |option| option != 'bar' }
|
291
|
+
end
|
292
|
+
|
293
|
+
app.action do |options, arguments|
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
it { subject.should == ["must be 'foo'", "must not be 'bar'"] }
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|