gli 2.19.2 → 2.20.0

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +28 -0
  3. data/.gitignore +1 -3
  4. data/Gemfile +0 -6
  5. data/README.rdoc +2 -12
  6. data/Rakefile +15 -37
  7. data/bin/ci +29 -0
  8. data/bin/gli +25 -64
  9. data/bin/rake +29 -0
  10. data/bin/setup +5 -0
  11. data/exe/gli +68 -0
  12. data/gli.gemspec +19 -21
  13. data/gli.rdoc +2 -2
  14. data/lib/gli/commands/help_modules/command_help_format.rb +1 -1
  15. data/lib/gli/commands/help_modules/global_help_format.rb +1 -1
  16. data/lib/gli/commands/scaffold.rb +9 -93
  17. data/lib/gli/options.rb +2 -2
  18. data/lib/gli/version.rb +1 -1
  19. data/object-model.dot +29 -0
  20. data/object-model.png +0 -0
  21. data/test/apps/todo/Gemfile +1 -1
  22. data/test/apps/todo/bin/todo +1 -1
  23. data/test/integration/gli_cli_test.rb +69 -0
  24. data/test/integration/gli_powered_app_test.rb +52 -0
  25. data/test/integration/scaffold_test.rb +30 -0
  26. data/test/integration/test_helper.rb +52 -0
  27. data/test/{tc_command_finder.rb → unit/command_finder_test.rb} +6 -6
  28. data/test/{tc_command.rb → unit/command_test.rb} +4 -4
  29. data/test/unit/compound_command_test.rb +17 -0
  30. data/test/{tc_doc.rb → unit/doc_test.rb} +38 -51
  31. data/test/{tc_flag.rb → unit/flag_test.rb} +19 -25
  32. data/test/{tc_gli.rb → unit/gli_test.rb} +28 -47
  33. data/test/{tc_help.rb → unit/help_test.rb} +48 -107
  34. data/test/{init_simplecov.rb → unit/init_simplecov.rb} +0 -0
  35. data/test/{tc_options.rb → unit/options_test.rb} +4 -4
  36. data/test/unit/subcommand_parsing_test.rb +263 -0
  37. data/test/unit/subcommands_test.rb +245 -0
  38. data/test/{fake_std_out.rb → unit/support/fake_std_out.rb} +0 -0
  39. data/test/{config.yaml → unit/support/gli_test_config.yml} +0 -0
  40. data/test/unit/switch_test.rb +49 -0
  41. data/test/{tc_terminal.rb → unit/terminal_test.rb} +4 -3
  42. data/test/unit/test_helper.rb +13 -0
  43. data/test/unit/verbatim_wrapper_test.rb +24 -0
  44. metadata +57 -124
  45. data/.ruby-gemset +0 -1
  46. data/.ruby-version +0 -1
  47. data/.travis.yml +0 -11
  48. data/ObjectModel.graffle +0 -1191
  49. data/bin/report_on_rake_results +0 -10
  50. data/bin/test_all_rubies.sh +0 -6
  51. data/features/gli_executable.feature +0 -90
  52. data/features/gli_init.feature +0 -236
  53. data/features/step_definitions/gli_executable_steps.rb +0 -18
  54. data/features/step_definitions/gli_init_steps.rb +0 -11
  55. data/features/step_definitions/todo_steps.rb +0 -100
  56. data/features/support/env.rb +0 -54
  57. data/features/support/hooks.rb +0 -5
  58. data/features/todo.feature +0 -579
  59. data/features/todo_legacy.feature +0 -130
  60. data/test/option_test_helper.rb +0 -13
  61. data/test/tc_compound_command.rb +0 -22
  62. data/test/tc_subcommand_parsing.rb +0 -280
  63. data/test/tc_subcommands.rb +0 -259
  64. data/test/tc_switch.rb +0 -55
  65. data/test/tc_verbatim_wrapper.rb +0 -36
  66. data/test/test_helper.rb +0 -21
@@ -1,259 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TC_testSubCommand < Clean::Test::TestCase
4
- include TestHelper
5
-
6
- def setup
7
- @fake_stdout = FakeStdOut.new
8
- @fake_stderr = FakeStdOut.new
9
-
10
- @original_stdout = $stdout
11
- $stdout = @fake_stdout
12
- @original_stderr = $stderr
13
- $stderr = @fake_stderr
14
-
15
- @app = CLIApp.new
16
- @app.reset
17
- @app.subcommand_option_handling :legacy
18
- @app.error_device=@fake_stderr
19
- ENV.delete('GLI_DEBUG')
20
- end
21
-
22
- def teardown
23
- $stdout = @original_stdout
24
- $stderr = @original_stderr
25
- end
26
-
27
- ['add','new'].each do |name|
28
- test_that "We run the 'add' subcommand using '#{name}'" do
29
- Given we_have_a_command_with_two_subcommands
30
- When run_app('remote',name,'-f','foo','bar')
31
- Then assert_command_ran_with(:add, :command_options => {:f => true}, :args => %w(foo bar))
32
- end
33
- end
34
-
35
- test_that "with subcommands, but not using one on the command-line, we run the base action" do
36
- Given we_have_a_command_with_two_subcommands
37
- When run_app('remote','foo','bar')
38
- Then assert_command_ran_with(:base, :command_options => {:f => false}, :args => %w(foo bar))
39
- end
40
-
41
- test_that "switches and flags defined on a subcommand are available" do
42
- Given we_have_a_command_with_two_subcommands(:switches => [:addswitch], :flags => [:addflag])
43
- When run_app('remote','add','--addswitch','--addflag','foo','bar')
44
- Then assert_command_ran_with(:add,:command_options => { :addswitch => true, :addflag => 'foo', :f => false },
45
- :args => ['bar'])
46
- end
47
-
48
- test_that "--help works for subcommands in :normal handling mode" do
49
- Given { @app.subcommand_option_handling :normal }
50
- And we_have_a_command_with_two_subcommands
51
- When { @app.run(["remote", "add", "--help"]) rescue nil }
52
- Then { assert_no_match /^error/, @fake_stderr.to_s, "should not output an error message" }
53
- end
54
-
55
- test_that "--help works for subcommands in :legacy handling mode" do
56
- Given { @app.subcommand_option_handling :legacy }
57
- And we_have_a_command_with_two_subcommands
58
- When { @app.run(["remote", "add", "--help"]) rescue nil }
59
- Then { assert_no_match /^error/, @fake_stderr.to_s, "should not output an error message" }
60
- end
61
-
62
- test_that "we can reopen commands to add new subcommands" do
63
- Given {
64
- @app.command :remote do |p|
65
- p.command :add do |c|
66
- c.action do |global_options,command_options,args|
67
- @ran_command = :add
68
- end
69
- end
70
- end
71
- @app.command :remote do |p|
72
- p.command :new do |c|
73
- c.action do |global_options,command_options,args|
74
- @ran_command = :new
75
- end
76
- end
77
- end
78
- }
79
- When run_app('remote','new')
80
- Then { assert_equal(@ran_command, :new) }
81
- When run_app('remote', 'add')
82
- Then { assert_equal(@ran_command, :add) }
83
- end
84
-
85
- test_that "reopening commands doesn't re-add them to the output" do
86
- Given {
87
- @app.command :remote do |p|
88
- p.command(:add) { }
89
- end
90
- @app.command :remote do |p|
91
- p.command(:new) { }
92
- end
93
- }
94
- command_names = @app.instance_variable_get("@commands_declaration_order").collect { |c| c.name }
95
- assert_equal 1, command_names.grep(:remote).size
96
- end
97
-
98
-
99
- test_that "we can reopen commands doesn't cause conflicts" do
100
- Given {
101
- @app.command :remote do |p|
102
- p.command :add do |c|
103
- c.action do |global_options,command_options,args|
104
- @ran_command = :remote_add
105
- end
106
- end
107
- end
108
- @app.command :local do |p|
109
- p.command :add do |c|
110
- c.action do |global_options,command_options,args|
111
- @ran_command = :local_add
112
- end
113
- end
114
- end
115
- }
116
- When run_app('remote','add')
117
- Then { assert_equal(@ran_command, :remote_add) }
118
- When run_app('local', 'add')
119
- Then { assert_equal(@ran_command, :local_add) }
120
- end
121
-
122
-
123
- test_that "we can nest subcommands very deep" do
124
- Given {
125
- @run_results = { :add => nil, :rename => nil, :base => nil }
126
- @app.command :remote do |c|
127
-
128
- c.switch :f
129
- c.command :add do |add|
130
- add.command :some do |some|
131
- some.command :cmd do |cmd|
132
- cmd.switch :s
133
- cmd.action do |global_options,command_options,args|
134
- @run_results[:cmd] = [global_options,command_options,args]
135
- end
136
- end
137
- end
138
- end
139
- end
140
- ENV['GLI_DEBUG'] = 'true'
141
- }
142
- When run_app('remote','add','some','cmd','-s','blah')
143
- Then assert_command_ran_with(:cmd, :command_options => {:s => true, :f => false},:args => ['blah'])
144
- end
145
-
146
- test_that "when any command in the chain has no action, but there's still arguments, indicate we have an unknown command" do
147
- Given a_very_deeply_nested_command_structure
148
- Then {
149
- assert_raises GLI::UnknownCommand do
150
- When run_app('remote','add','some','foo')
151
- end
152
- assert_match /Unknown command 'foo'/,@fake_stderr.to_s
153
- }
154
- end
155
-
156
- test_that "when a command in the chain has no action, but there's NO additional arguments, indicate we need a subcommand" do
157
- Given a_very_deeply_nested_command_structure
158
- Then {
159
- assert_raises GLI::BadCommandLine do
160
- When run_app('remote','add','some')
161
- end
162
- assert_match /Command 'some' requires a subcommand/,@fake_stderr.to_s
163
- }
164
- end
165
-
166
- private
167
-
168
- def run_app(*args)
169
- lambda { @exit_code = @app.run(args) }
170
- end
171
-
172
- def a_very_deeply_nested_command_structure
173
- lambda {
174
- @run_results = { :add => nil, :rename => nil, :base => nil }
175
- @app.command :remote do |c|
176
-
177
- c.switch :f
178
- c.command :add do |add|
179
- add.command :some do |some|
180
- some.command :cmd do |cmd|
181
- cmd.switch :s
182
- cmd.action do |global_options,command_options,args|
183
- @run_results[:cmd] = [global_options,command_options,args]
184
- end
185
- end
186
- end
187
- end
188
- end
189
- ENV['GLI_DEBUG'] = 'true'
190
- }
191
- end
192
-
193
- # expected_command - name of command exepcted to have been run
194
- # options:
195
- # - global_options => hash of expected options
196
- # - command_options => hash of expected command options
197
- # - args => array of expected args
198
- def assert_command_ran_with(expected_command,options)
199
- lambda {
200
- global_options = options[:global_options] || { :help => false }
201
- @run_results.each do |command,results|
202
- if command == expected_command
203
- assert_equal(indifferent_hash(global_options),results[0])
204
- assert_equal(indifferent_hash(options[:command_options]),results[1])
205
- assert_equal(options[:args],results[2])
206
- else
207
- assert_nil results
208
- end
209
- end
210
- }
211
- end
212
-
213
- def indifferent_hash(possibly_nil_hash)
214
- return {} if possibly_nil_hash.nil?
215
- possibly_nil_hash.keys.each do |key|
216
- if key.kind_of? Symbol
217
- possibly_nil_hash[key.to_s] = possibly_nil_hash[key] unless possibly_nil_hash.has_key?(key.to_s)
218
- elsif key.kind_of? String
219
- possibly_nil_hash[key.to_sym] = possibly_nil_hash[key] unless possibly_nil_hash.has_key?(key.to_sym)
220
- end
221
- end
222
- possibly_nil_hash
223
- end
224
-
225
- # options -
226
- # :flags => flags to add to :add
227
- # :switiches => switiches to add to :add
228
- def we_have_a_command_with_two_subcommands(options = {})
229
- lambda {
230
- @run_results = { :add => nil, :rename => nil, :base => nil }
231
- @app.command :remote do |c|
232
-
233
- c.switch :f
234
-
235
- c.desc "add a remote"
236
- c.command [:add,:new] do |add|
237
-
238
- Array(options[:flags]).each { |_| add.flag _ }
239
- Array(options[:switches]).each { |_| add.switch _ }
240
- add.action do |global_options,command_options,args|
241
- @run_results[:add] = [global_options,command_options,args]
242
- end
243
- end
244
-
245
- c.desc "rename a remote"
246
- c.command :rename do |rename|
247
- rename.action do |global_options,command_options,args|
248
- @run_results[:rename] = [global_options,command_options,args]
249
- end
250
- end
251
-
252
- c.action do |global_options,command_options,args|
253
- @run_results[:base] = [global_options,command_options,args]
254
- end
255
- end
256
- ENV['GLI_DEBUG'] = 'true'
257
- }
258
- end
259
- end
data/test/tc_switch.rb DELETED
@@ -1,55 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TC_testSwitch < Clean::Test::TestCase
4
- include TestHelper
5
-
6
- def test_basics_simple
7
- Given switch_with_names(:filename)
8
- Then attributes_should_be_set
9
- And name_should_be(:filename)
10
- And aliases_should_be(nil)
11
- end
12
-
13
- def test_basics_kinda_complex
14
- Given switch_with_names([:f])
15
- Then attributes_should_be_set
16
- And name_should_be(:f)
17
- And aliases_should_be(nil)
18
- end
19
-
20
- def test_basics_complex
21
- Given switch_with_names([:f,:file,:filename])
22
- Then attributes_should_be_set
23
- And name_should_be(:f)
24
- And aliases_should_be([:file,:filename])
25
- And {
26
- assert_equal ["-f","--[no-]file","--[no-]filename"],@switch.arguments_for_option_parser
27
- }
28
- end
29
-
30
- def test_includes_negatable
31
- assert_equal '-a',GLI::Switch.name_as_string('a')
32
- assert_equal '--[no-]foo',GLI::Switch.name_as_string('foo')
33
- end
34
-
35
- private
36
-
37
- def switch_with_names(names)
38
- lambda do
39
- @options = {
40
- :desc => 'Filename',
41
- :long_desc => 'The Filename',
42
- }
43
- @switch = GLI::Switch.new(names,@options)
44
- @cli_option = @switch
45
- end
46
- end
47
-
48
- def attributes_should_be_set
49
- lambda {
50
- assert_equal(@options[:desc],@switch.description)
51
- assert_equal(@options[:long_desc],@switch.long_description)
52
- }
53
- end
54
-
55
- end
@@ -1,36 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TC_testVerbatimWrapper < Clean::Test::TestCase
4
- include TestHelper
5
-
6
- test_that "verbatim wrapper handles nil" do
7
- Given {
8
- @wrapper = GLI::Commands::HelpModules::VerbatimWrapper.new(any_int,any_int)
9
- }
10
- When {
11
- @result = @wrapper.wrap(nil)
12
- }
13
- Then {
14
- assert_equal '',@result
15
- }
16
- end
17
-
18
- test_that "verbatim wrapper doesn't touch the input" do
19
- Given {
20
- @wrapper = GLI::Commands::HelpModules::VerbatimWrapper.new(any_int,any_int)
21
- @input = <<EOS
22
- |This is|an ASCII|table|
23
- +-------+--------+-----+
24
- | foo | bar | baz |
25
- +-------+--------+-----+
26
- EOS
27
- }
28
- When {
29
- @result = @wrapper.wrap(@input)
30
- }
31
- Then {
32
- assert_equal @input,@result
33
- }
34
- end
35
-
36
- end
data/test/test_helper.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'rubygems'
2
- require 'gli.rb'
3
- require 'test/unit'
4
- require 'clean_test/test_case'
5
- require 'fake_std_out'
6
- require 'option_test_helper'
7
-
8
- module TestHelper
9
- include OptionTestHelper
10
- class CLIApp
11
- include GLI::App
12
-
13
- def reset
14
- super
15
- @subcommand_option_handling_strategy = :normal
16
- end
17
- end
18
- end
19
-
20
- Faker::Config.locale = :en
21
- I18n.enforce_available_locales = false