gli 2.18.2 → 2.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +28 -0
  3. data/.gitignore +1 -3
  4. data/.tool-versions +1 -1
  5. data/Gemfile +0 -6
  6. data/README.rdoc +33 -23
  7. data/Rakefile +21 -37
  8. data/bin/ci +29 -0
  9. data/bin/gli +25 -64
  10. data/bin/rake +29 -0
  11. data/bin/setup +5 -0
  12. data/exe/gli +68 -0
  13. data/gli.gemspec +19 -22
  14. data/gli.rdoc +2 -2
  15. data/lib/gli/command_support.rb +2 -6
  16. data/lib/gli/commands/help_modules/arg_name_formatter.rb +2 -2
  17. data/lib/gli/commands/help_modules/command_help_format.rb +1 -1
  18. data/lib/gli/commands/help_modules/global_help_format.rb +1 -1
  19. data/lib/gli/commands/scaffold.rb +9 -93
  20. data/lib/gli/dsl.rb +1 -1
  21. data/lib/gli/options.rb +2 -2
  22. data/lib/gli/version.rb +1 -1
  23. data/object-model.dot +29 -0
  24. data/object-model.png +0 -0
  25. data/test/apps/todo/Gemfile +1 -1
  26. data/test/apps/todo/bin/todo +1 -1
  27. data/test/integration/gli_cli_test.rb +69 -0
  28. data/test/integration/gli_powered_app_test.rb +52 -0
  29. data/test/integration/scaffold_test.rb +30 -0
  30. data/test/integration/test_helper.rb +52 -0
  31. data/test/{tc_command_finder.rb → unit/command_finder_test.rb} +6 -6
  32. data/test/{tc_command.rb → unit/command_test.rb} +4 -4
  33. data/test/unit/compound_command_test.rb +17 -0
  34. data/test/{tc_doc.rb → unit/doc_test.rb} +38 -51
  35. data/test/{tc_flag.rb → unit/flag_test.rb} +19 -25
  36. data/test/{tc_gli.rb → unit/gli_test.rb} +28 -47
  37. data/test/{tc_help.rb → unit/help_test.rb} +48 -107
  38. data/test/{init_simplecov.rb → unit/init_simplecov.rb} +0 -0
  39. data/test/{tc_options.rb → unit/options_test.rb} +4 -4
  40. data/test/unit/subcommand_parsing_test.rb +263 -0
  41. data/test/unit/subcommands_test.rb +245 -0
  42. data/test/{fake_std_out.rb → unit/support/fake_std_out.rb} +0 -0
  43. data/test/{config.yaml → unit/support/gli_test_config.yml} +0 -0
  44. data/test/unit/switch_test.rb +49 -0
  45. data/test/{tc_terminal.rb → unit/terminal_test.rb} +4 -3
  46. data/test/unit/test_helper.rb +13 -0
  47. data/test/unit/verbatim_wrapper_test.rb +24 -0
  48. metadata +74 -139
  49. data/.ruby-gemset +0 -1
  50. data/.ruby-version +0 -1
  51. data/.travis.yml +0 -11
  52. data/ObjectModel.graffle +0 -1191
  53. data/bin/report_on_rake_results +0 -10
  54. data/bin/test_all_rubies.sh +0 -6
  55. data/features/gli_executable.feature +0 -90
  56. data/features/gli_init.feature +0 -235
  57. data/features/step_definitions/gli_executable_steps.rb +0 -18
  58. data/features/step_definitions/gli_init_steps.rb +0 -11
  59. data/features/step_definitions/todo_steps.rb +0 -100
  60. data/features/support/env.rb +0 -54
  61. data/features/todo.feature +0 -579
  62. data/features/todo_legacy.feature +0 -130
  63. data/test/option_test_helper.rb +0 -13
  64. data/test/tc_compound_command.rb +0 -22
  65. data/test/tc_subcommand_parsing.rb +0 -280
  66. data/test/tc_subcommands.rb +0 -259
  67. data/test/tc_switch.rb +0 -55
  68. data/test/tc_verbatim_wrapper.rb +0 -36
  69. data/test/test_helper.rb +0 -21
@@ -1,6 +1,6 @@
1
- require 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
- class TC_testHelp < Clean::Test::TestCase
3
+ class HelpTest < MiniTest::Test
4
4
  include TestHelper
5
5
 
6
6
  def setup
@@ -24,86 +24,61 @@ class TC_testHelp < Clean::Test::TestCase
24
24
  include GLI::App
25
25
  end
26
26
 
27
- test_that "the help command is configured properly when created" do
28
- Given {
29
- app = TestApp.new
30
- app.subcommand_option_handling :normal
31
- @command = GLI::Commands::Help.new(app,@output,@error)
32
- }
33
- Then {
34
- assert_equal 'help',@command.name.to_s
35
- assert_nil @command.aliases
36
- assert_equal 'command',@command.arguments_description
37
- assert_not_nil @command.description
38
- assert_not_nil @command.long_description
39
- assert @command.skips_pre
40
- assert @command.skips_post
41
- assert @command.skips_around
42
- }
27
+ def test_help_command_configured_properly_when_created
28
+ app = TestApp.new
29
+ app.subcommand_option_handling :normal
30
+ @command = GLI::Commands::Help.new(app,@output,@error)
31
+ assert_equal 'help',@command.name.to_s
32
+ assert_nil @command.aliases
33
+ assert_equal 'command',@command.arguments_description
34
+ refute_nil @command.description
35
+ refute_nil @command.long_description
36
+ assert @command.skips_pre
37
+ assert @command.skips_post
38
+ assert @command.skips_around
43
39
  end
44
40
 
45
- test_that "the help command can be configured to skip things declaratively" do
46
- Given {
41
+ def test_the_help_command_can_be_configured_to_skip_things_declaratively
47
42
  app = TestApp.new
48
43
  app.subcommand_option_handling :normal
49
44
  @command = GLI::Commands::Help.new(app,@output,@error)
50
45
  GLI::Commands::Help.skips_pre = false
51
46
  GLI::Commands::Help.skips_post = false
52
47
  GLI::Commands::Help.skips_around = false
53
- }
54
- Then {
55
48
  assert !@command.skips_pre
56
49
  assert !@command.skips_post
57
50
  assert !@command.skips_around
58
- }
59
51
  end
60
52
 
61
- test_that "the help command can be configured to skip things declaratively regardless of when the object was created" do
62
- Given {
53
+ def test_the_help_command_can_be_configured_to_skip_things_declaratively_regardless_of_when_the_object_was_created
63
54
  GLI::Commands::Help.skips_pre = false
64
55
  GLI::Commands::Help.skips_post = false
65
56
  GLI::Commands::Help.skips_around = false
66
57
  app = TestApp.new
67
58
  app.subcommand_option_handling :normal
68
59
  @command = GLI::Commands::Help.new(app,@output,@error)
69
- }
70
- Then {
71
60
  assert !@command.skips_pre
72
61
  assert !@command.skips_post
73
62
  assert !@command.skips_around
74
- }
75
63
  end
76
64
 
77
- test_that "invoking help with no arguments results in listing all commands and global options" do
78
- Given a_GLI_app
79
- And {
65
+ def test_invoking_help_with_no_arguments_results_in_listing_all_commands_and_global_options
66
+ setup_GLI_app
80
67
  @command = GLI::Commands::Help.new(@app,@output,@error)
81
- }
82
- When {
83
68
  @command.execute({},{},[])
84
- }
85
- Then {
86
69
  assert_top_level_help_output
87
- }
88
70
  end
89
71
 
90
- test_that "invoking help with a command that doesn't exist shows an error" do
91
- Given a_GLI_app
92
- And {
72
+ def test_invoking_help_with_a_command_that_doesnt_exist_shows_an_error
73
+ setup_GLI_app
93
74
  @command = GLI::Commands::Help.new(@app,@output,@error)
94
75
  @unknown_command_name = any_command_name
95
- }
96
- When {
97
76
  @command.execute({},{},[@unknown_command_name])
98
- }
99
- Then {
100
77
  assert_error_contained(/error: Unknown command '#{@unknown_command_name}'./)
101
- }
102
78
  end
103
79
 
104
- test_that "invoking help with a known command shows help for that command" do
105
- Given a_GLI_app
106
- And {
80
+ def test_invoking_help_with_a_known_command_shows_help_for_that_command
81
+ setup_GLI_app
107
82
  @command_name = cm = any_command_name
108
83
  @desc = d = any_desc
109
84
  @long_desc = ld = any_desc
@@ -127,11 +102,7 @@ class TC_testHelp < Clean::Test::TestCase
127
102
  end
128
103
  end
129
104
  @command = GLI::Commands::Help.new(@app,@output,@error)
130
- }
131
- When {
132
105
  @command.execute({},{},[@command_name])
133
- }
134
- Then {
135
106
  assert_output_contained(@command_name,"Name of the command")
136
107
  assert_output_contained(@desc,"Short description")
137
108
  assert_output_contained(@long_desc,"Long description")
@@ -139,27 +110,19 @@ class TC_testHelp < Clean::Test::TestCase
139
110
  assert_output_contained(@switch_desc,"switch description")
140
111
  assert_output_contained("-" + @flag,"command flag")
141
112
  assert_output_contained(@flag_desc,"flag description")
142
- }
143
113
  end
144
114
 
145
- test_that 'invoking help for an app with no global options omits [global options] from the usage string' do
146
- Given a_GLI_app(:no_options)
147
- And {
115
+ def test_invoking_help_with_no_global_options_omits_the_global_options_placeholder_from_usage
116
+ setup_GLI_app(:no_options)
148
117
  @command = GLI::Commands::Help.new(@app,@output,@error)
149
- }
150
- When {
151
118
  @command.execute({},{},[])
152
- }
153
- Then {
154
119
  refute_output_contained(/\[global options\] command \[command options\] \[arguments\.\.\.\]/)
155
120
  refute_output_contained('GLOBAL OPTIONS')
156
121
  assert_output_contained(/command \[command options\] \[arguments\.\.\.\]/)
157
- }
158
122
  end
159
123
 
160
- test_that "invoking help with a known command when no global options are present omits [global options] from the usage string" do
161
- Given a_GLI_app(:no_options)
162
- And {
124
+ def test_invoking_help_with_a_known_command_when_no_global_options_are_present_omits_placeholder_from_the_usage_string
125
+ setup_GLI_app(:no_options)
163
126
  @command_name = cm = any_command_name
164
127
  @desc = d = any_desc
165
128
  @long_desc = ld = any_desc
@@ -183,20 +146,14 @@ class TC_testHelp < Clean::Test::TestCase
183
146
  end
184
147
  end
185
148
  @command = GLI::Commands::Help.new(@app,@output,@error)
186
- }
187
- When {
188
149
  @command.execute({},{},[@command_name])
189
- }
190
- Then {
191
150
  refute_output_contained(/\[global options\]/)
192
151
  assert_output_contained(/\[command options\]/)
193
152
  assert_output_contained('COMMAND OPTIONS')
194
- }
195
153
  end
196
154
 
197
- test_that "invoking help with a known command when no global options nor command options are present omits [global options] and [command options] from the usage string" do
198
- Given a_GLI_app(:no_options)
199
- And {
155
+ def test_omits_both_placeholders_when_no_options_present
156
+ setup_GLI_app(:no_options)
200
157
  @command_name = cm = any_command_name
201
158
  @desc = d = any_desc
202
159
  @long_desc = ld = any_desc
@@ -209,20 +166,14 @@ class TC_testHelp < Clean::Test::TestCase
209
166
  end
210
167
  end
211
168
  @command = GLI::Commands::Help.new(@app,@output,@error)
212
- }
213
- When {
214
169
  @command.execute({},{},[@command_name])
215
- }
216
- Then {
217
170
  refute_output_contained(/\[global options\]/)
218
171
  refute_output_contained(/\[command options\]/)
219
172
  refute_output_contained('COMMAND OPTIONS')
220
- }
221
173
  end
222
174
 
223
- test_that "invoking help with a known command that has no command options omits [command options] from the usage string" do
224
- Given a_GLI_app
225
- And {
175
+ def test_no_command_options_omits_command_options_placeholder
176
+ setup_GLI_app
226
177
  @command_name = cm = any_command_name
227
178
  @desc = d = any_desc
228
179
  @long_desc = ld = any_desc
@@ -235,19 +186,13 @@ class TC_testHelp < Clean::Test::TestCase
235
186
  end
236
187
  end
237
188
  @command = GLI::Commands::Help.new(@app,@output,@error)
238
- }
239
- When {
240
189
  @command.execute({},{},[@command_name])
241
- }
242
- Then {
243
190
  assert_output_contained(/\[global options\]/)
244
191
  refute_output_contained(/\[command options\]/)
245
192
  refute_output_contained('COMMAND OPTIONS')
246
- }
247
193
  end
248
194
 
249
- test_that "omitting default_description doesn't blow up" do
250
- Given {
195
+ def test_omitting_default_description_doesnt_blow_up
251
196
  app = TestApp.new
252
197
  app.instance_eval do
253
198
  subcommand_option_handling :normal
@@ -266,23 +211,20 @@ class TC_testHelp < Clean::Test::TestCase
266
211
  end
267
212
  end
268
213
  @command = GLI::Commands::Help.new(app,@output,@error)
269
- }
270
- When {
271
- @code = lambda { @command.execute({},{},['top']) }
272
- }
273
- Then {
274
- assert_nothing_raised(&@code)
275
- }
214
+ begin
215
+ @command.execute({},{},['top'])
216
+ rescue => ex
217
+ assert false, "Expected no exception, got: #{ex.message}"
218
+ end
276
219
  end
277
220
 
278
221
  private
279
222
 
280
- def a_GLI_app(omit_options=false)
281
- lambda {
223
+ def setup_GLI_app(omit_options=false)
282
224
  @program_description = program_description = any_desc
283
225
  @flags = flags = [
284
- [any_desc.strip,any_arg_name,[any_option]],
285
- [any_desc.strip,any_arg_name,[any_option,any_long_option]],
226
+ [any_desc.strip,:foo,[any_option]],
227
+ [any_desc.strip,:bar,[any_option,any_long_option]],
286
228
  ]
287
229
  @switches = switches = [
288
230
  [any_desc.strip,[any_option]],
@@ -319,7 +261,6 @@ private
319
261
  end
320
262
  end
321
263
  end
322
- }
323
264
  end
324
265
 
325
266
  def assert_top_level_help_output
@@ -357,7 +298,7 @@ private
357
298
 
358
299
  def refute_output_contained(string_or_regexp,desc='')
359
300
  string_or_regexp = /#{string_or_regexp}/ if string_or_regexp.kind_of?(String)
360
- assert_no_match string_or_regexp,@output.string,desc
301
+ refute_match string_or_regexp,@output.string,desc
361
302
  end
362
303
 
363
304
  def any_option
@@ -365,21 +306,21 @@ private
365
306
  end
366
307
 
367
308
  def any_long_option
368
- Faker::Lorem.words(10)[rand(10)]
369
- end
370
-
371
- def any_arg_name
372
- any_string :max => 20
309
+ ["foo","bar","blah"].sample
373
310
  end
374
311
 
375
312
  def any_desc
376
- Faker::Lorem.words(10).join(' ')[0..30].gsub(/\s*$/,'')
313
+ [
314
+ "This command does some stuff",
315
+ "Do things and whatnot",
316
+ "Behold the power of this command"
317
+ ].sample
377
318
  end
378
319
 
379
320
  def any_command_name
380
- command_name = Faker::Lorem.words(10)[rand(10)]
321
+ command_name = ["new","edit","delete","create","update"].sample
381
322
  while @command_names_used.include?(command_name)
382
- command_name = Faker::Lorem.words(10)[rand(10)]
323
+ command_name = ["new","edit","delete","create","update"].sample
383
324
  end
384
325
  @command_names_used << command_name
385
326
  command_name
File without changes
@@ -1,6 +1,6 @@
1
- require 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
- class TC_testOptions < Clean::Test::TestCase
3
+ class OptiosnTest < MiniTest::Test
4
4
  include TestHelper
5
5
 
6
6
  def test_by_method
@@ -10,7 +10,7 @@ class TC_testOptions < Clean::Test::TestCase
10
10
  assert_equal 'verbose', o[:name]
11
11
  assert_equal 'verbose', o['name']
12
12
  end
13
-
13
+
14
14
  def test_by_string
15
15
  o = GLI::Options.new
16
16
  o['name'] = 'verbose'
@@ -18,7 +18,7 @@ class TC_testOptions < Clean::Test::TestCase
18
18
  assert_equal 'verbose', o[:name]
19
19
  assert_equal 'verbose', o['name']
20
20
  end
21
-
21
+
22
22
  def test_by_symbol
23
23
  o = GLI::Options.new
24
24
  o[:name] = 'verbose'
@@ -0,0 +1,263 @@
1
+ require_relative "test_helper"
2
+ require_relative "support/fake_std_out"
3
+
4
+ class SubcommandParsingTest < MiniTest::Test
5
+ include TestHelper
6
+
7
+ def setup
8
+ @fake_stdout = FakeStdOut.new
9
+ @fake_stderr = FakeStdOut.new
10
+
11
+ @original_stdout = $stdout
12
+ $stdout = @fake_stdout
13
+ @original_stderr = $stderr
14
+ $stderr = @fake_stderr
15
+
16
+ @app = CLIApp.new
17
+ @app.reset
18
+ @app.subcommand_option_handling :legacy
19
+ @app.error_device=@fake_stderr
20
+ ENV.delete('GLI_DEBUG')
21
+
22
+ @results = {}
23
+ @exit_code = 0
24
+ end
25
+
26
+ def teardown
27
+ $stdout = @original_stdout
28
+ $stderr = @original_stderr
29
+ end
30
+
31
+ def test_commands_options_may_clash_with_globals_and_it_gets_sorted_out
32
+ setup_app_with_subcommands_storing_results
33
+ @app.run(%w(-f global command1 -f command -s foo))
34
+ assert_equal 'command1',@results[:command_name]
35
+ assert_equal 'global', @results[:global_options][:f],'global'
36
+ assert !@results[:global_options][:s]
37
+ assert_equal 'command', @results[:command_options][:f]
38
+ assert @results[:command_options][:s]
39
+ end
40
+
41
+ def test_in_legacy_mode_subcommand_options_all_share_a_namespace
42
+ setup_app_with_subcommands_storing_results
43
+ @app.run(%w(-f global command1 -f command -s subcommand10 -f sub))
44
+ with_clue {
45
+ assert_equal 'subcommand10',@results[:command_name]
46
+ assert_equal 'global', @results[:global_options][:f],'global'
47
+ assert !@results[:global_options][:s]
48
+ assert_equal 'sub', @results[:command_options][:f]
49
+ assert @results[:command_options][:s]
50
+ assert_nil @results[:command_options][GLI::Command::PARENT]
51
+ assert_nil @results[:command_options][GLI::Command::PARENT]
52
+ }
53
+ end
54
+
55
+ def test_in_normal_mode_each_subcommand_has_its_own_namespace
56
+ setup_app_with_subcommands_storing_results :normal
57
+ @app.run(%w(-f global command1 -f command -s subcommand10 -f sub))
58
+ with_clue {
59
+ assert_equal 'subcommand10',@results[:command_name]
60
+ assert_equal 'global', @results[:global_options][:f],'global'
61
+ assert !@results[:global_options][:s]
62
+ assert_equal 'sub', @results[:command_options][:f]
63
+ assert !@results[:command_options][:s]
64
+ assert_equal 'command',@results[:command_options][GLI::Command::PARENT][:f]
65
+ assert @results[:command_options][GLI::Command::PARENT][:s]
66
+ }
67
+ end
68
+
69
+ def test_in_loose_mode_with_autocomplete_false_it_doesnt_autocorrect_a_sub_command
70
+ setup_app_with_subcommand_storing_results :normal, false, :loose
71
+ @app.run(%w(-f global command -f flag -s subcomm -f subflag))
72
+ with_clue {
73
+ assert_equal "command",@results[:command_name]
74
+ }
75
+ end
76
+
77
+ def test_in_strict_mode_with_autocomplete_false_it_doesnt_autocorrect_a_sub_command
78
+ setup_app_with_subcommand_storing_results :normal, false, :strict
79
+ @app.run(%w(-f global command -f flag -s subcomm -f subflag))
80
+ with_clue {
81
+ assert_equal nil,@results[:command_name]
82
+ assert @fake_stderr.contained?(/error: Too many arguments for command/)
83
+ }
84
+ end
85
+
86
+ def test_in_loose_mode_argument_validation_is_ignored
87
+ setup_app_with_arguments 1, 1, false, :loose
88
+ run_app_with_X_arguments 0
89
+ with_clue {
90
+ assert_equal 0, @results[:number_of_args_give_to_action]
91
+ assert_equal 0, @exit_code
92
+ }
93
+ end
94
+
95
+ def test_in_strict_mode_subcommand_option_handling_must_be_normal
96
+ setup_app_with_arguments 1, 1, false, :strict, :legacy
97
+ run_app_with_X_arguments 1
98
+ with_clue {
99
+ assert_nil @results[:number_of_args_give_to_action]
100
+ assert_equal 1, @exit_code
101
+ assert @fake_stderr.contained?(/you must enable normal subcommand_option_handling/)
102
+ }
103
+ end
104
+
105
+ [
106
+ [1 , 1 , false , 1 ] ,
107
+ [1 , 1 , false , 2 ] ,
108
+ [1 , 1 , true , 1 ] ,
109
+ [1 , 1 , true , 2 ] ,
110
+ [1 , 1 , true , 3 ] ,
111
+ [1 , 1 , true , 30 ] ,
112
+ [0 , 0 , false , 0 ] ,
113
+ [0 , 1 , false , 1 ] ,
114
+ [0 , 1 , false , 0 ] ,
115
+ [1 , 0 , false , 1 ] ,
116
+ [0 , 0 , true , 0 ] ,
117
+ [0 , 0 , true , 10 ]
118
+
119
+ ].each do |number_required, number_optional, has_multiple, number_generated|
120
+ define_method "test_strict_options_success_cases_#{number_required}_#{number_optional}_#{has_multiple}_#{number_generated}" do
121
+ setup_app_with_arguments number_required, number_optional, has_multiple, :strict
122
+ run_app_with_X_arguments number_generated
123
+ with_clue {
124
+ assert_equal number_generated, @results[:number_of_args_give_to_action]
125
+ assert_equal 0, @exit_code
126
+ assert !@fake_stderr.contained?(/Not enough arguments for command/)
127
+ assert !@fake_stderr.contained?(/Too many arguments for command/)
128
+ }
129
+ end
130
+ end
131
+
132
+ [
133
+ [1 , 1 , false , 3 , :too_many] ,
134
+ [0 , 0 , false , 1 , :too_many] ,
135
+ [1 , 1 , false , 0 , :not_enough] ,
136
+ [1 , 1 , true , 0 , :not_enough] ,
137
+ [1 , 0 , false , 0 , :not_enough] ,
138
+
139
+ ].each do |number_required, number_optional, has_multiple, number_generated, status|
140
+ define_method "test_strict_options_failure_cases_#{number_required}_#{number_optional}_#{has_multiple}_#{number_generated}_#{status}" do
141
+ setup_app_with_arguments number_required, number_optional, has_multiple, :strict
142
+ run_app_with_X_arguments number_generated
143
+ with_clue {
144
+ if status == :not_enough then
145
+ assert_nil @results[:number_of_args_give_to_action]
146
+ assert_equal 64, @exit_code
147
+ assert @fake_stderr.contained?(/Not enough arguments for command/)
148
+ elsif status == :too_many then
149
+ assert_nil @results[:number_of_args_give_to_action]
150
+ assert_equal 64, @exit_code
151
+ assert @fake_stderr.contained?(/Too many arguments for command/)
152
+ else
153
+ assert false
154
+ end
155
+ }
156
+ end
157
+ end
158
+
159
+ private
160
+ def with_clue(&block)
161
+ block.call
162
+ rescue Exception
163
+ dump = ""
164
+ PP.pp "\nRESULTS---#{@results}", dump unless @results.empty?
165
+ PP.pp "\nSTDERR---\n#{@fake_stderr.to_s}", dump
166
+ PP.pp "\nSTDOUT---\n#{@fake_stdout.to_s}", dump
167
+ @original_stdout.puts dump
168
+ raise
169
+ end
170
+
171
+ def setup_app_with_subcommand_storing_results(subcommand_option_handling_strategy, autocomplete, arguments_handling_strategy)
172
+ @app.subcommand_option_handling subcommand_option_handling_strategy
173
+ @app.autocomplete_commands autocomplete
174
+ @app.arguments arguments_handling_strategy
175
+ @app.flag ['f','flag']
176
+ @app.switch ['s','switch']
177
+
178
+ @app.command "command" do |c|
179
+ c.flag ['f','flag']
180
+ c.switch ['s','switch']
181
+ c.action do |global,options,args|
182
+ @results = {
183
+ :command_name => "command",
184
+ :global_options => global,
185
+ :command_options => options,
186
+ :args => args
187
+ }
188
+ end
189
+
190
+ c.command "subcommand" do |subcommand|
191
+ subcommand.flag ['f','flag']
192
+ subcommand.flag ['foo']
193
+ subcommand.switch ['s','switch']
194
+ subcommand.action do |global,options,args|
195
+ @results = {
196
+ :command_name => "subcommand",
197
+ :global_options => global,
198
+ :command_options => options,
199
+ :args => args
200
+ }
201
+ end
202
+ end
203
+ end
204
+ end
205
+
206
+ def setup_app_with_subcommands_storing_results(subcommand_option_handling_strategy = :legacy)
207
+ @app.subcommand_option_handling subcommand_option_handling_strategy
208
+ @app.flag ['f','flag']
209
+ @app.switch ['s','switch']
210
+
211
+ 2.times do |i|
212
+ @app.command "command#{i}" do |c|
213
+ c.flag ['f','flag']
214
+ c.switch ['s','switch']
215
+ c.action do |global,options,args|
216
+ @results = {
217
+ :command_name => "command#{i}",
218
+ :global_options => global,
219
+ :command_options => options,
220
+ :args => args
221
+ }
222
+ end
223
+
224
+ 2.times do |j|
225
+ c.command "subcommand#{i}#{j}" do |subcommand|
226
+ subcommand.flag ['f','flag']
227
+ subcommand.flag ['foo']
228
+ subcommand.switch ['s','switch']
229
+ subcommand.action do |global,options,args|
230
+ @results = {
231
+ :command_name => "subcommand#{i}#{j}",
232
+ :global_options => global,
233
+ :command_options => options,
234
+ :args => args
235
+ }
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
241
+ end
242
+
243
+ def setup_app_with_arguments(number_required_arguments, number_optional_arguments, has_argument_multiple, arguments_handling_strategy = :loose, subcommand_option_handling_strategy = :normal)
244
+ @app.arguments arguments_handling_strategy
245
+ @app.subcommand_option_handling subcommand_option_handling_strategy
246
+
247
+ number_required_arguments.times { |i| @app.arg("needed#{i}") }
248
+ number_optional_arguments.times { |i| @app.arg("optional#{i}", :optional) }
249
+ @app.arg :multiple, [:multiple, :optional] if has_argument_multiple
250
+
251
+ @app.command :cmd do |c|
252
+ c.action do |g,o,a|
253
+ @results = {
254
+ :number_of_args_give_to_action => a.size
255
+ }
256
+ end
257
+ end
258
+ end
259
+
260
+ def run_app_with_X_arguments(number_arguments)
261
+ @exit_code = @app.run [].tap{|args| args << "cmd"; number_arguments.times {|i| args << "arg#{i}"}}
262
+ end
263
+ end