convoy 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.irbrc +3 -0
  4. data/.rspec +3 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +8 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +22 -0
  9. data/README.md +705 -0
  10. data/Rakefile +1 -0
  11. data/convoy.gemspec +24 -0
  12. data/examples/.my_apprc +24 -0
  13. data/examples/basic +10 -0
  14. data/examples/basic_config_file +16 -0
  15. data/examples/basic_conflicts +17 -0
  16. data/examples/basic_depends_on +25 -0
  17. data/examples/basic_flags +15 -0
  18. data/examples/basic_options +14 -0
  19. data/examples/basic_options_multi +15 -0
  20. data/examples/basic_require_arguments +17 -0
  21. data/examples/basic_texts +21 -0
  22. data/examples/basic_validations +21 -0
  23. data/examples/basic_with_everything +30 -0
  24. data/examples/commands/example_command.rb +13 -0
  25. data/examples/suite_complex +65 -0
  26. data/examples/suite_simple +19 -0
  27. data/examples/suite_with_sub_commands +94 -0
  28. data/lib/convoy.rb +83 -0
  29. data/lib/convoy/action_command/base.rb +85 -0
  30. data/lib/convoy/action_command/escort_utility_command.rb +53 -0
  31. data/lib/convoy/app.rb +127 -0
  32. data/lib/convoy/arguments.rb +20 -0
  33. data/lib/convoy/auto_options.rb +71 -0
  34. data/lib/convoy/error/error.rb +33 -0
  35. data/lib/convoy/formatter/command.rb +87 -0
  36. data/lib/convoy/formatter/commands.rb +37 -0
  37. data/lib/convoy/formatter/cursor_position.rb +29 -0
  38. data/lib/convoy/formatter/default_help_formatter.rb +117 -0
  39. data/lib/convoy/formatter/global_command.rb +17 -0
  40. data/lib/convoy/formatter/option.rb +152 -0
  41. data/lib/convoy/formatter/options.rb +28 -0
  42. data/lib/convoy/formatter/shell_command_executor.rb +49 -0
  43. data/lib/convoy/formatter/stream_output_formatter.rb +88 -0
  44. data/lib/convoy/formatter/string_grid.rb +108 -0
  45. data/lib/convoy/formatter/string_splitter.rb +50 -0
  46. data/lib/convoy/formatter/terminal.rb +30 -0
  47. data/lib/convoy/global_pre_parser.rb +43 -0
  48. data/lib/convoy/logger.rb +75 -0
  49. data/lib/convoy/option_dependency_validator.rb +82 -0
  50. data/lib/convoy/option_parser.rb +155 -0
  51. data/lib/convoy/setup/configuration/generator.rb +75 -0
  52. data/lib/convoy/setup/configuration/instance.rb +34 -0
  53. data/lib/convoy/setup/configuration/loader.rb +43 -0
  54. data/lib/convoy/setup/configuration/locator/base.rb +19 -0
  55. data/lib/convoy/setup/configuration/locator/chaining.rb +29 -0
  56. data/lib/convoy/setup/configuration/locator/descending_to_home.rb +23 -0
  57. data/lib/convoy/setup/configuration/locator/executing_script_directory.rb +15 -0
  58. data/lib/convoy/setup/configuration/locator/specified_directory.rb +21 -0
  59. data/lib/convoy/setup/configuration/merge_tool.rb +38 -0
  60. data/lib/convoy/setup/configuration/reader.rb +36 -0
  61. data/lib/convoy/setup/configuration/writer.rb +46 -0
  62. data/lib/convoy/setup/dsl/action.rb +17 -0
  63. data/lib/convoy/setup/dsl/command.rb +67 -0
  64. data/lib/convoy/setup/dsl/config_file.rb +13 -0
  65. data/lib/convoy/setup/dsl/global.rb +29 -0
  66. data/lib/convoy/setup/dsl/options.rb +81 -0
  67. data/lib/convoy/setup_accessor.rb +206 -0
  68. data/lib/convoy/trollop.rb +861 -0
  69. data/lib/convoy/utils.rb +21 -0
  70. data/lib/convoy/validator.rb +45 -0
  71. data/spec/integration/basic_config_file_spec.rb +126 -0
  72. data/spec/integration/basic_conflicts_spec.rb +47 -0
  73. data/spec/integration/basic_depends_on_spec.rb +275 -0
  74. data/spec/integration/basic_options_spec.rb +41 -0
  75. data/spec/integration/basic_options_with_multi_spec.rb +30 -0
  76. data/spec/integration/basic_spec.rb +38 -0
  77. data/spec/integration/basic_validations_spec.rb +77 -0
  78. data/spec/integration/basic_with_arguments_spec.rb +35 -0
  79. data/spec/integration/basic_with_text_fields_spec.rb +21 -0
  80. data/spec/integration/suite_simple_spec.rb +45 -0
  81. data/spec/integration/suite_sub_command_spec.rb +51 -0
  82. data/spec/lib/convoy/action_command/base_spec.rb +200 -0
  83. data/spec/lib/convoy/formatter/command_spec.rb +238 -0
  84. data/spec/lib/convoy/formatter/global_command_spec.rb +50 -0
  85. data/spec/lib/convoy/formatter/option_spec.rb +300 -0
  86. data/spec/lib/convoy/formatter/shell_command_executor_spec.rb +59 -0
  87. data/spec/lib/convoy/formatter/stream_output_formatter_spec.rb +214 -0
  88. data/spec/lib/convoy/formatter/string_grid_spec.rb +59 -0
  89. data/spec/lib/convoy/formatter/string_splitter_spec.rb +50 -0
  90. data/spec/lib/convoy/formatter/terminal_spec.rb +19 -0
  91. data/spec/lib/convoy/setup/configuration/generator_spec.rb +101 -0
  92. data/spec/lib/convoy/setup/configuration/loader_spec.rb +79 -0
  93. data/spec/lib/convoy/setup/configuration/locator/chaining_spec.rb +81 -0
  94. data/spec/lib/convoy/setup/configuration/locator/descending_to_home_spec.rb +57 -0
  95. data/spec/lib/convoy/setup/configuration/locator/executing_script_directory_spec.rb +29 -0
  96. data/spec/lib/convoy/setup/configuration/locator/specified_directory_spec.rb +33 -0
  97. data/spec/lib/convoy/setup/configuration/merge_tool_spec.rb +41 -0
  98. data/spec/lib/convoy/setup/configuration/reader_spec.rb +41 -0
  99. data/spec/lib/convoy/setup/configuration/writer_spec.rb +75 -0
  100. data/spec/lib/convoy/setup_accessor_spec.rb +226 -0
  101. data/spec/lib/convoy/utils_spec.rb +30 -0
  102. data/spec/spec_helper.rb +29 -0
  103. data/spec/support/integration_helpers.rb +2 -0
  104. data/spec/support/matchers/execute_action_for_command_matcher.rb +21 -0
  105. data/spec/support/matchers/execute_action_with_arguments_matcher.rb +25 -0
  106. data/spec/support/matchers/execute_action_with_options_matcher.rb +29 -0
  107. data/spec/support/matchers/exit_with_code_matcher.rb +29 -0
  108. data/spec/support/shared_contexts/integration_setup.rb +34 -0
  109. metadata +292 -0
@@ -0,0 +1,59 @@
1
+ describe Convoy::Formatter::ShellCommandExecutor do
2
+ let(:executor) { Convoy::Formatter::ShellCommandExecutor.new(command) }
3
+ let(:result) { [] }
4
+ let(:error_callback) { lambda { |command, error| result << 'error'; result << error.class } }
5
+
6
+ #describe "#execute_in_new_shell" do
7
+ #subject {executor.execute_in_new_shell(success_callback, error_callback)}
8
+
9
+ #let(:success_callback) {lambda{ |command, stdin, stdout, stderr| result << 'success' }}
10
+
11
+ #context "when command is invalid" do
12
+ #let(:command) { 'lx -z' }
13
+ #it("error callback should be executed") {subject; result.first.should == 'error'}
14
+ #it("should return nil") {subject.should be_nil}
15
+ #end
16
+
17
+ #context "when command is valid" do
18
+ #context "but options passed to it are invalid" do
19
+ #let(:command) { 'ls --foobar' }
20
+ #it("error callback should be executed") {subject; result.first.should == 'error'}
21
+ #it("command should produce an exit status error") {subject; result[1].should == Convoy::InternalError}
22
+ #it("should return nil") {subject.should be_nil}
23
+ #end
24
+
25
+ #context "and options passed to it are valid" do
26
+ #let(:command) { 'ls -al' }
27
+ #it("success callback should be executed") {subject; result.first.should == 'success'}
28
+ #it("should not return nil") {subject.should_not be_nil}
29
+ #end
30
+ #end
31
+ #end
32
+
33
+ describe "#execute_in_current_shell" do
34
+ subject { executor.execute_in_current_shell(success_callback, error_callback) }
35
+
36
+ let(:success_callback) { lambda { |command, final_result| result << 'success' } }
37
+
38
+ context "when command is invalid" do
39
+ let(:command) { 'lx -z' }
40
+ it("error callback should be executed") { subject; result.first.should == 'error' }
41
+ it("should return nil") { subject.should be_nil }
42
+ end
43
+
44
+ context "when command is valid" do
45
+ context "but options passed to it are invalid" do
46
+ let(:command) { 'ls --foobar' }
47
+ it("error callback should be executed") { subject; result.first.should == 'error' }
48
+ it("command should produce an exit status error") { subject; result[1].should == Convoy::InternalError }
49
+ it("should return nil") { subject.should be_nil }
50
+ end
51
+
52
+ context "and options passed to it are valid" do
53
+ let(:command) { 'ls -al' }
54
+ it("success callback should be executed") { subject; result.first.should == 'success' }
55
+ it("should not return nil") { subject.should_not be_nil }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,214 @@
1
+ describe Convoy::Formatter::StreamOutputFormatter do
2
+ let(:formatter) { Convoy::Formatter::StreamOutputFormatter.new(stream, :max_output_width => output_width) }
3
+ let(:stream) { StringIO.new }
4
+ let(:output_width) { 10 }
5
+ let(:output) { stream.readlines }
6
+
7
+ describe "#print" do
8
+ subject { formatter.print(string) }
9
+
10
+ before { subject; stream.rewind }
11
+
12
+ context "when string is less than output_width" do
13
+ let(:string) { '12345' }
14
+ it("stream should have one line") { output.first.should == string }
15
+ end
16
+
17
+ context "when string is greater than output width" do
18
+ let(:string) { '123456789abcd' }
19
+ it("stream should have two lines") { output.should == ["123456789a\n", "bcd"] }
20
+ end
21
+
22
+ context "when string is has newlines in it" do
23
+ context "and both lines less than output width" do
24
+ let(:string) { "1234567\n89abcd" }
25
+ it("stream should have two lines") { output.should == ["1234567\n", "89abcd"] }
26
+ end
27
+
28
+ context "and first line greater than output width" do
29
+ let(:string) { "123456789abcd\nefg" }
30
+ it("stream should have three lines") { output.should == ["123456789a\n", "bcd\n", "efg"] }
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#puts" do
36
+ subject { formatter.puts(string, options) }
37
+ let(:string) { 'hello' }
38
+ let(:options) { {:newlines => newlines} }
39
+ let(:newlines) { 1 }
40
+
41
+ before { subject; stream.rewind }
42
+
43
+ context "when newlines" do
44
+ context "is zero" do
45
+ let(:newlines) { 0 }
46
+ let(:string) { "123456789abcd\nefg" }
47
+ it("stream should have three lines") { output.should == ["123456789a\n", "bcd\n", "efg"] }
48
+ end
49
+
50
+ context "not specified" do
51
+ subject { formatter.puts(string) }
52
+ let(:string) { "123" }
53
+ it("stream should have one newline") { output.should == ["123\n"] }
54
+ end
55
+
56
+ context "is two" do
57
+ let(:string) { "123" }
58
+ let(:newlines) { 2 }
59
+ it("stream should have two newlines") { output.should == ["123\n", "\n"] }
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "#newline" do
65
+ subject { formatter.newline(newline_count) }
66
+ let(:newline_count) { 1 }
67
+
68
+ before { subject; stream.rewind }
69
+
70
+ context "when newline count not specified" do
71
+ subject { formatter.newline }
72
+ it("stream should have one newline") { output.should == ["\n"] }
73
+ end
74
+
75
+ context "when newline count is 2" do
76
+ let(:newline_count) { 2 }
77
+ it("stream should have two newlines") { output.should == ["\n", "\n"] }
78
+ end
79
+ end
80
+
81
+ describe "#indent" do
82
+ subject { formatter.indent(indent_width, &indented_block) }
83
+
84
+ let(:indented_block) do
85
+ lambda { |f| f.print string }
86
+ end
87
+
88
+ before { subject; stream.rewind }
89
+
90
+ context "when indent is 0" do
91
+ let(:indent_width) { 0 }
92
+
93
+ context "and we print a string less than output_width" do
94
+ let(:string) { '12345' }
95
+ it("stream should have one line") { output.should == ['12345'] }
96
+ end
97
+
98
+ context "and we print a string greater than output width" do
99
+ let(:string) { '123456789abcd' }
100
+ it("stream should have two lines") { output.should == ["123456789a\n", "bcd"] }
101
+ end
102
+
103
+ context "and we print a string that has newlines in it" do
104
+ context "and both lines are less than output width" do
105
+ let(:string) { "1234567\n89abcd" }
106
+ it("stream should have two lines") { output.should == ["1234567\n", "89abcd"] }
107
+ end
108
+
109
+ context "and first line is greater than output width" do
110
+ let(:string) { "123456789abcd\nefg" }
111
+ it("stream should have three lines") { output.should == ["123456789a\n", "bcd\n", "efg"] }
112
+ end
113
+ end
114
+ end
115
+
116
+ context "when indent is 1" do
117
+ let(:indent_width) { 1 }
118
+
119
+ context "and we print a string less than output_width" do
120
+ let(:string) { '12345' }
121
+ it("stream should have one line") { output.should == [' 12345'] }
122
+ end
123
+
124
+ context "and we print a string greater than output width" do
125
+ let(:string) { '123456789abcd' }
126
+ it("stream should have two lines") { output.should == [" 123456789\n", " abcd"] }
127
+ end
128
+
129
+ context "and we print a string that has newlines in it" do
130
+ context "and both lines are less than output width" do
131
+ let(:string) { "1234567\n89abcd" }
132
+ it("stream should have two lines") { output.should == [" 1234567\n", " 89abcd"] }
133
+ end
134
+
135
+ context "and first line is greater than output width" do
136
+ let(:string) { "123456789abcd\nefg" }
137
+ it("stream should have three lines") { output.should == [" 123456789\n", " abcd\n", " efg"] }
138
+ end
139
+ end
140
+ end
141
+
142
+ context "when indent is 3" do
143
+ let(:indent_width) { 3 }
144
+
145
+ context "and we print a string less than output_width" do
146
+ let(:string) { '12345' }
147
+ it("stream should have one line") { output.should == [' 12345'] }
148
+ end
149
+
150
+ context "and we print a string greater than output width" do
151
+ let(:string) { '123456789abcd' }
152
+ it("stream should have two lines") { output.should == [" 1234567\n", " 89abcd"] }
153
+ end
154
+
155
+ context "and we print a string that has newlines in it" do
156
+ context "and both lines are less than output width" do
157
+ let(:string) { "1234567\n89abcd" }
158
+ it("stream should have two lines") { output.should == [" 1234567\n", " 89abcd"] }
159
+ end
160
+
161
+ context "and first line is greater than output width" do
162
+ let(:string) { "123456789abcd\nefg" }
163
+ it("stream should have three lines") { output.should == [" 1234567\n", " 89abcd\n", " efg"] }
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ context "output combinations" do
170
+ subject do
171
+ Convoy::Formatter::StreamOutputFormatter.new(stream, :max_output_width => output_width) do |f|
172
+ f.print "the quick"
173
+ f.newline
174
+ f.print "brown fox"
175
+ f.print "jumped over the"
176
+ f.print "lazy dog"
177
+ f.newline
178
+ f.puts 'rainbow suspenders'
179
+ f.indent(3) do |f|
180
+ f.puts "blah blah blah blah"
181
+ f.newline(2)
182
+ f.indent(2) do |f|
183
+ f.puts "indent me good"
184
+ f.print "foo"
185
+ f.print "foo"
186
+ f.print "foo"
187
+ f.newline
188
+ f.puts "exit", :newlines => 4
189
+ end
190
+ end
191
+ end
192
+ end
193
+ let(:stream) { StringIO.new }
194
+ let(:output_width) { 10 }
195
+
196
+ let(:output) { stream.readlines }
197
+
198
+ before { subject; stream.rewind }
199
+
200
+ context "lines should not be greater than output width" do
201
+ it do
202
+ output.each do |line|
203
+ line.strip.length.should be <= output_width
204
+ end
205
+ end
206
+ end
207
+
208
+ context "stream should contain" do
209
+ it do
210
+ output.should == ["the quick\n", "brown foxj\n", "umped over\n", " thelazy d\n", "og\n", "rainbow su\n", "spenders\n", " blah bl\n", " ah blah\n", " blah\n", "\n", "\n", " inden\n", " t me \n", " good\n", " foofo\n", " ofoo\n", " exit\n", "\n", "\n", "\n"]
211
+ end
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,59 @@
1
+ describe Convoy::Formatter::StringGrid do
2
+ let(:width) { 20 }
3
+
4
+ describe "#to_s" do
5
+ subject { grid.to_s }
6
+
7
+ context "when 2 rows and 3 columns" do
8
+ context "no strings span multiple rows" do
9
+ let(:grid) do
10
+ Convoy::Formatter::StringGrid.new(:columns => 3, :width => width) do |g|
11
+ g.row 'a', 'b', 'c'
12
+ g.row 1, 2, 3
13
+ end
14
+ end
15
+ it("all rows should equal table width") do
16
+ subject.split("\n").each do |val|
17
+ val.length.should == width
18
+ end
19
+ end
20
+ it { subject.should == "a b c \n1 2 3 " }
21
+ end
22
+
23
+ context "first column string spans 4 rows" do
24
+ let(:grid) do
25
+ Convoy::Formatter::StringGrid.new(:columns => 3, :width => width) do |g|
26
+ g.row '123456789abcdefgh', 'b', 'c'
27
+ g.row 1, 2, 3
28
+ end
29
+ end
30
+ it("should have 5 rows") do
31
+ subject.split("\n").size.should == 5
32
+ end
33
+ it("all rows should equal table width") do
34
+ subject.split("\n").each do |val|
35
+ val.length.should == width
36
+ end
37
+ end
38
+ it { subject.should == "12345 b c \n6789a \nbcdef \ngh \n1 2 3 " }
39
+ end
40
+ context "last column string spans 2 rows" do
41
+ let(:grid) do
42
+ Convoy::Formatter::StringGrid.new(:columns => 3, :width => width) do |g|
43
+ g.row 'a', 'b', 'c'
44
+ g.row 1, 2, "123456789abcdefghijk"
45
+ end
46
+ end
47
+ it("should have 3 rows") do
48
+ subject.split("\n").size.should == 3
49
+ end
50
+ it("all rows should equal table width") do
51
+ subject.split("\n").each do |val|
52
+ val.length.should == width
53
+ end
54
+ end
55
+ it { subject.should == "a b c \n1 2 123456789abcdef \n ghijk " }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,50 @@
1
+ describe Convoy::Formatter::StringSplitter do
2
+ let(:splitter) { Convoy::Formatter::StringSplitter.new(max_segment_width) }
3
+
4
+ describe "#split" do
5
+ subject { splitter.split(string) }
6
+
7
+ context "when segment width is 10" do
8
+ let(:max_segment_width) { 10 }
9
+
10
+ context "and string is 'abc123'" do
11
+ let(:string) { 'abc123' }
12
+ it("should produce 1 segment") { subject.size.should == 1 }
13
+ it("first segment should be 'abc123'") { subject[0].should == 'abc123' }
14
+ end
15
+
16
+ context "and string is 'abc1234567'" do
17
+ let(:string) { 'abc1234567' }
18
+ it("should produce 1 segment") { subject.size.should == 1 }
19
+ it("first segment should be 'abc1234567'") { subject[0].should == 'abc1234567' }
20
+ end
21
+
22
+ context "and string is 'abc123abc456'" do
23
+ let(:string) { 'abc123abc456' }
24
+ it("should produce 2 segments") { subject.size.should == 2 }
25
+ it("first segment should be 'abc123abc4'") { subject[0].should == 'abc123abc4' }
26
+ it("first segment should be '56'") { subject[1].should == '56' }
27
+ end
28
+
29
+ context "and string is 'abc123abc456bbbcccddd'" do
30
+ let(:string) { 'abc123abc456bbbcccddd' }
31
+ it("should produce 3 segments") { subject.size.should == 3 }
32
+ it("first segment should be 'abc123abc4'") { subject[0].should == 'abc123abc4' }
33
+ it("first segment should be '56bbbcccdd'") { subject[1].should == '56bbbcccdd' }
34
+ it("first segment should be 'd'") { subject[2].should == 'd' }
35
+ end
36
+ end
37
+
38
+ context "when segment width is 5" do
39
+ let(:max_segment_width) { 5 }
40
+
41
+ context "and string is 'abc\\n123456'" do
42
+ let(:string) { "abc\n123456" }
43
+ it("should produce 3 segments") { subject.size.should == 3 }
44
+ it("first segment should be 'abc'") { subject[0].should == 'abc' }
45
+ it("second segment should be '12345'") { subject[1].should == '12345' }
46
+ it("last segment should be '6'") { subject[2].should == '6' }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,19 @@
1
+ describe Convoy::Formatter::Terminal do
2
+ let(:terminal) { Convoy::Formatter::Terminal }
3
+
4
+ describe "#width" do
5
+ subject { terminal.width }
6
+
7
+ context "when width can be found successfully" do
8
+ let(:current_width) { `/usr/bin/env tput cols`.to_i }
9
+ it("should be equal to current width") { subject.should == current_width }
10
+ end
11
+
12
+ context "when width could not be found successfully" do
13
+ before do
14
+ Convoy::Formatter::ShellCommandExecutor.any_instance.stub(:execute_in_current_shell).and_return(nil)
15
+ end
16
+ it("should be equal to default width") { subject.should == Convoy::Formatter::Terminal::DEFAULT_WIDTH }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,101 @@
1
+ describe Convoy::Setup::Configuration::Generator do
2
+
3
+ let(:generator) { Convoy::Setup::Configuration::Generator.new(setup) }
4
+ let(:setup) { Convoy::SetupAccessor.new(app_configuration) }
5
+
6
+
7
+ describe "#default_data" do
8
+ subject { generator.default_data }
9
+
10
+ context "when basic configuration" do
11
+ let(:app_configuration) do
12
+ Convoy::Setup::Dsl::Global.new do |app|
13
+ app.options do |opts|
14
+ opts.opt :option1, "option1", :short => :none, :long => '--option1', :type => :string
15
+ end
16
+
17
+ app.action do |options, arguments|
18
+ end
19
+ end
20
+ end
21
+ it("should have a user config") { subject[:user].should_not be_nil }
22
+ it("user config should be empty") { subject[:user].should be_empty }
23
+ it("shoud have a global config") { subject[:global].should_not be_nil }
24
+ it("global config should not be empty") { subject[:global].should_not be_empty }
25
+ it("should have a global commands config") { subject[:global][:commands].should_not be_nil }
26
+ it("global commands config should be empty") { subject[:global][:commands].should be_empty }
27
+ it("should have a global options config") { subject[:global][:options].should_not be_nil }
28
+ it("global options config should not be empty") { subject[:global][:options].should_not be_empty }
29
+ it("options config should have a key for configured option") { subject[:global][:options].keys.size.should == 1 }
30
+ it("options config key for configured config should be nil when no default value") { subject[:global][:options][:option1].should be_nil }
31
+
32
+ context "and configured option has default value" do
33
+ let(:app_configuration) do
34
+ Convoy::Setup::Dsl::Global.new do |app|
35
+ app.options do |opts|
36
+ opts.opt :option1, "option1", :short => :none, :long => '--option1', :type => :string, :default => "hello"
37
+ end
38
+
39
+ app.action do |options, arguments|
40
+ end
41
+ end
42
+ end
43
+ it("options config key for configured config should equal to default value") { subject[:global][:options][:option1].should == 'hello' }
44
+ end
45
+ end
46
+
47
+ context "when suite configuration" do
48
+ let(:app_configuration) do
49
+ Convoy::Setup::Dsl::Global.new do |app|
50
+ app.options do |opts|
51
+ opts.opt :option1, "option1", :short => :none, :long => '--option1', :type => :string
52
+ end
53
+
54
+ app.command :command1, :aliases => [:c1, :com1] do |command|
55
+ command.options do |opts|
56
+ opts.opt :option2, "option2", :short => :none, :long => '--option2', :type => :string, :default => 'blah'
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ it("should have a global commands config") { subject[:global][:commands].should_not be_nil }
63
+ it("global commands config should be empty") { subject[:global][:commands].should_not be_empty }
64
+ it("command1 commands config should not be nil") { subject[:global][:commands][:command1][:commands].should_not be_nil }
65
+ it("command1 commands config should be empty") { subject[:global][:commands][:command1][:commands].should be_empty }
66
+ it("command1 options config should not be nil") { subject[:global][:commands][:command1][:options].should_not be_nil }
67
+ it("command1 options config should not be empty") { subject[:global][:commands][:command1][:options].should_not be_empty }
68
+ it("command1 options option value should be the same as default value") { subject[:global][:commands][:command1][:options][:option2].should == 'blah' }
69
+ end
70
+
71
+ context "when suite with sub commands configuration" do
72
+ let(:app_configuration) do
73
+ Convoy::Setup::Dsl::Global.new do |app|
74
+ app.options do |opts|
75
+ opts.opt :option1, "option1", :short => :none, :long => '--option1', :type => :string
76
+ end
77
+
78
+ app.command :command1, :aliases => [:c1, :com1] do |command|
79
+ command.options do |opts|
80
+ opts.opt :option2, "option2", :short => :none, :long => '--option2', :type => :string, :default => 'blah'
81
+ end
82
+
83
+ command.command :sub_command1 do |command|
84
+ command.options do |opts|
85
+ opts.opt :option3, "option3", :short => :none, :long => '--option3', :type => :string, :default => 'yadda'
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ it("command1 commands config should not be nil") { subject[:global][:commands][:command1][:commands].should_not be_nil }
93
+ it("command1 commands config should not be empty") { subject[:global][:commands][:command1][:commands].should_not be_empty }
94
+ it("sub_command1 command config should not be nil") { subject[:global][:commands][:command1][:commands][:sub_command1][:commands].should_not be_nil }
95
+ it("sub_command1 command config should be empty") { subject[:global][:commands][:command1][:commands][:sub_command1][:commands].should be_empty }
96
+ it("sub_command1 options config should not be nil") { subject[:global][:commands][:command1][:commands][:sub_command1][:options].should_not be_nil }
97
+ it("sub_command1 options config should not be empty") { subject[:global][:commands][:command1][:commands][:sub_command1][:options].should_not be_empty }
98
+ it("sub_command1 options option value should be the same as default value") { subject[:global][:commands][:command1][:commands][:sub_command1][:options][:option3].should == 'yadda' }
99
+ end
100
+ end
101
+ end