gli 2.19.2 → 2.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +28 -0
- data/.gitignore +1 -3
- data/Gemfile +0 -6
- data/README.rdoc +2 -12
- data/Rakefile +15 -37
- data/bin/ci +29 -0
- data/bin/gli +25 -64
- data/bin/rake +29 -0
- data/bin/setup +5 -0
- data/exe/gli +68 -0
- data/gli.gemspec +19 -21
- data/gli.rdoc +2 -2
- data/lib/gli/commands/help_modules/command_help_format.rb +1 -1
- data/lib/gli/commands/help_modules/global_help_format.rb +1 -1
- data/lib/gli/commands/scaffold.rb +9 -93
- data/lib/gli/options.rb +2 -2
- data/lib/gli/version.rb +1 -1
- data/object-model.dot +29 -0
- data/object-model.png +0 -0
- data/test/apps/todo/Gemfile +1 -1
- data/test/apps/todo/bin/todo +1 -1
- data/test/integration/gli_cli_test.rb +69 -0
- data/test/integration/gli_powered_app_test.rb +52 -0
- data/test/integration/scaffold_test.rb +30 -0
- data/test/integration/test_helper.rb +52 -0
- data/test/{tc_command_finder.rb → unit/command_finder_test.rb} +6 -6
- data/test/{tc_command.rb → unit/command_test.rb} +4 -4
- data/test/unit/compound_command_test.rb +17 -0
- data/test/{tc_doc.rb → unit/doc_test.rb} +38 -51
- data/test/{tc_flag.rb → unit/flag_test.rb} +19 -25
- data/test/{tc_gli.rb → unit/gli_test.rb} +28 -47
- data/test/{tc_help.rb → unit/help_test.rb} +48 -107
- data/test/{init_simplecov.rb → unit/init_simplecov.rb} +0 -0
- data/test/{tc_options.rb → unit/options_test.rb} +4 -4
- data/test/unit/subcommand_parsing_test.rb +263 -0
- data/test/unit/subcommands_test.rb +245 -0
- data/test/{fake_std_out.rb → unit/support/fake_std_out.rb} +0 -0
- data/test/{config.yaml → unit/support/gli_test_config.yml} +0 -0
- data/test/unit/switch_test.rb +49 -0
- data/test/{tc_terminal.rb → unit/terminal_test.rb} +4 -3
- data/test/unit/test_helper.rb +13 -0
- data/test/unit/verbatim_wrapper_test.rb +24 -0
- metadata +57 -124
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -11
- data/ObjectModel.graffle +0 -1191
- data/bin/report_on_rake_results +0 -10
- data/bin/test_all_rubies.sh +0 -6
- data/features/gli_executable.feature +0 -90
- data/features/gli_init.feature +0 -236
- data/features/step_definitions/gli_executable_steps.rb +0 -18
- data/features/step_definitions/gli_init_steps.rb +0 -11
- data/features/step_definitions/todo_steps.rb +0 -100
- data/features/support/env.rb +0 -54
- data/features/support/hooks.rb +0 -5
- data/features/todo.feature +0 -579
- data/features/todo_legacy.feature +0 -130
- data/test/option_test_helper.rb +0 -13
- data/test/tc_compound_command.rb +0 -22
- data/test/tc_subcommand_parsing.rb +0 -280
- data/test/tc_subcommands.rb +0 -259
- data/test/tc_switch.rb +0 -55
- data/test/tc_verbatim_wrapper.rb +0 -36
- data/test/test_helper.rb +0 -21
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
3
|
+
class CommandFinderTest < MiniTest::Test
|
4
4
|
include TestHelper
|
5
5
|
|
6
6
|
def setup
|
@@ -14,13 +14,13 @@ class TC_testCommandFinder < Clean::Test::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_unknown_command_name
|
17
|
-
|
17
|
+
assert_raises(GLI::UnknownCommand) do
|
18
18
|
GLI::CommandFinder.new(@app.commands, :default_command => :status).find_command(:unfindable_command)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_no_command_name_without_default
|
23
|
-
|
23
|
+
assert_raises(GLI::UnknownCommand) do
|
24
24
|
GLI::CommandFinder.new(@app.commands).find_command(nil)
|
25
25
|
end
|
26
26
|
end
|
@@ -33,7 +33,7 @@ class TC_testCommandFinder < Clean::Test::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_ambigous_command
|
36
|
-
|
36
|
+
assert_raises(GLI::AmbiguousCommand) do
|
37
37
|
GLI::CommandFinder.new(@app.commands, :default_command => :status).find_command(:some)
|
38
38
|
end
|
39
39
|
end
|
@@ -46,7 +46,7 @@ class TC_testCommandFinder < Clean::Test::TestCase
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_partial_name_with_autocorrect_disabled
|
49
|
-
|
49
|
+
assert_raises(GLI::UnknownCommand) do
|
50
50
|
GLI::CommandFinder.new(@app.commands, :default_command => :status, :autocomplete => false)
|
51
51
|
.find_command(:deploy)
|
52
52
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative "test_helper"
|
2
|
+
require_relative "support/fake_std_out"
|
3
3
|
|
4
|
-
class
|
4
|
+
class CommandTest < MiniTest::Test
|
5
5
|
include TestHelper
|
6
6
|
def setup
|
7
7
|
@fake_stdout = FakeStdOut.new
|
@@ -436,7 +436,7 @@ class TC_testCommand < Clean::Test::TestCase
|
|
436
436
|
private
|
437
437
|
|
438
438
|
def assert_contained(output,regexp)
|
439
|
-
|
439
|
+
refute_nil output.contained?(regexp),
|
440
440
|
"Expected output to contain #{regexp.inspect}, output was:\n#{output}"
|
441
441
|
end
|
442
442
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class CompoundCommandFinderTest < MiniTest::Test
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def test_exception_for_missing_commands
|
7
|
+
@name = "new"
|
8
|
+
@unknown_name = "create"
|
9
|
+
@existing_command = OpenStruct.new(:name => @name)
|
10
|
+
@base = OpenStruct.new( :commands => { @name => @existing_command })
|
11
|
+
|
12
|
+
@code = lambda { GLI::Commands::CompoundCommand.new(@base,{:foo => [@name,@unknown_name]}) }
|
13
|
+
|
14
|
+
ex = assert_raises(RuntimeError,&@code)
|
15
|
+
assert_match /#{Regexp.escape(@unknown_name)}/,ex.message
|
16
|
+
end
|
17
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'pp'
|
1
|
+
require_relative "test_helper"
|
3
2
|
|
4
3
|
class String
|
5
4
|
def blank?
|
@@ -19,7 +18,7 @@ class Object
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
class
|
21
|
+
class DocTest < MiniTest::Test
|
23
22
|
include TestHelper
|
24
23
|
|
25
24
|
class TestApp
|
@@ -112,42 +111,30 @@ class TC_testDoc < Clean::Test::TestCase
|
|
112
111
|
@@counter = -1 # we pre-increment so this makes 0 first
|
113
112
|
end
|
114
113
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
lines_expected = @string.split(/\n/)
|
127
|
-
lines_got = @listener.to_s.split(/\n/)
|
128
|
-
lines_expected.zip(lines_got).each_with_index do |(expected,got),index|
|
129
|
-
assert_equal expected,got,"At index #{index}"
|
130
|
-
end
|
131
|
-
}
|
114
|
+
def test_app_without_docs_gets_callbacks_for_each_element
|
115
|
+
setup_test_app
|
116
|
+
construct_expected_output
|
117
|
+
@documenter = GLI::Commands::Doc.new(@app)
|
118
|
+
@listener = TestListener.new
|
119
|
+
@documenter.document(@listener)
|
120
|
+
lines_expected = @string.split(/\n/)
|
121
|
+
lines_got = @listener.to_s.split(/\n/)
|
122
|
+
lines_expected.zip(lines_got).each_with_index do |(expected,got),index|
|
123
|
+
assert_equal expected,got,"At index #{index}"
|
124
|
+
end
|
132
125
|
end
|
133
126
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
lines_expected = @string.split(/\n/)
|
146
|
-
lines_got = TestListener.last.to_s.split(/\n/)
|
147
|
-
lines_expected.zip(lines_got).each_with_index do |(expected,got),index|
|
148
|
-
assert_equal expected,got,"At index #{index}"
|
149
|
-
end
|
150
|
-
}
|
127
|
+
def test_doc_command_works_as_GLI_command
|
128
|
+
setup_test_app
|
129
|
+
construct_expected_output
|
130
|
+
@documenter = GLI::Commands::Doc.new(@app)
|
131
|
+
@listener = TestListener.new
|
132
|
+
@documenter.execute({},{:format => "DocTest::TestListener"},[])
|
133
|
+
lines_expected = @string.split(/\n/)
|
134
|
+
lines_got = TestListener.last.to_s.split(/\n/)
|
135
|
+
lines_expected.zip(lines_got).each_with_index do |(expected,got),index|
|
136
|
+
assert_equal expected,got,"At index #{index}"
|
137
|
+
end
|
151
138
|
end
|
152
139
|
|
153
140
|
private
|
@@ -158,36 +145,36 @@ private
|
|
158
145
|
@@counter
|
159
146
|
end
|
160
147
|
|
161
|
-
def
|
148
|
+
def setup_test_app
|
162
149
|
@app = TestApp.new
|
163
150
|
@app.instance_eval do
|
164
151
|
program_desc "program desc"
|
165
152
|
program_long_desc "program long desc"
|
166
153
|
version "1.3.4"
|
167
154
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
155
|
+
DocTest.flag_with_everything_specified(self)
|
156
|
+
DocTest.flag_with_everything_omitted(self)
|
157
|
+
DocTest.switch_with_everything_specified(self)
|
158
|
+
DocTest.switch_with_everything_omitted(self)
|
172
159
|
|
173
160
|
desc "command desc"
|
174
161
|
long_desc "command long desc"
|
175
162
|
arg_name "cmd_arg_name"
|
176
163
|
command [:command1,:com1] do |c|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
164
|
+
DocTest.flag_with_everything_specified(c)
|
165
|
+
DocTest.flag_with_everything_omitted(c)
|
166
|
+
DocTest.switch_with_everything_specified(c)
|
167
|
+
DocTest.switch_with_everything_omitted(c)
|
181
168
|
|
182
169
|
c.desc "subcommand desc"
|
183
170
|
c.long_desc "subcommand long desc"
|
184
171
|
c.arg_name "subcmd_arg_name"
|
185
172
|
c.action { |g,o,a| }
|
186
173
|
c.command [:sub,:subcommand] do |sub|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
174
|
+
DocTest.flag_with_everything_specified(sub,:subflag)
|
175
|
+
DocTest.flag_with_everything_omitted(sub,:subflag2)
|
176
|
+
DocTest.switch_with_everything_specified(sub,:subswitch)
|
177
|
+
DocTest.switch_with_everything_omitted(sub,:subswitch2)
|
191
178
|
sub.action { |g,o,a| }
|
192
179
|
end
|
193
180
|
c.command [:default] do |sub|
|
@@ -227,7 +214,7 @@ private
|
|
227
214
|
def self.switch_with_everything_omitted(on,name=[:S,:switch2])
|
228
215
|
on.switch name
|
229
216
|
end
|
230
|
-
def
|
217
|
+
def construct_expected_output
|
231
218
|
# Oh yeah. Creating a string representing the structure of the calls.
|
232
219
|
@string =<<EOS
|
233
220
|
BEGIN
|
@@ -1,39 +1,36 @@
|
|
1
|
-
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
3
|
+
class FlagTest < MiniTest::Test
|
4
4
|
include TestHelper
|
5
5
|
|
6
6
|
def test_basics_simple
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
setup_for_flag_with_names(:f)
|
8
|
+
assert_attributes_set
|
9
|
+
assert_equal(:f,@cli_option.name)
|
10
|
+
assert_nil @cli_option.aliases
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_basics_kinda_complex
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
setup_for_flag_with_names([:f])
|
15
|
+
assert_attributes_set
|
16
|
+
assert_equal(:f,@cli_option.name)
|
17
|
+
assert_nil @cli_option.aliases
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_basics_complex
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
assert_equal ["-f VAL","--file VAL","--filename VAL",/foobar/,Float],@flag.arguments_for_option_parser
|
27
|
-
}
|
21
|
+
setup_for_flag_with_names([:f,:file,:filename])
|
22
|
+
assert_attributes_set
|
23
|
+
assert_equal(:f,@cli_option.name)
|
24
|
+
assert_equal [:file,:filename], @cli_option.aliases
|
25
|
+
assert_equal ["-f VAL","--file VAL","--filename VAL",/foobar/,Float],@flag.arguments_for_option_parser
|
28
26
|
end
|
29
27
|
|
30
28
|
def test_flag_can_mask_its_value
|
31
|
-
|
32
|
-
|
29
|
+
setup_for_flag_with_names(:password, :mask => true)
|
30
|
+
assert_attributes_set(:safe_default_value => "********")
|
33
31
|
end
|
34
32
|
|
35
|
-
def
|
36
|
-
lambda do
|
33
|
+
def setup_for_flag_with_names(names,options = {})
|
37
34
|
@options = {
|
38
35
|
:desc => 'Filename',
|
39
36
|
:long_desc => 'The Filename',
|
@@ -45,11 +42,9 @@ class TC_testFlag < Clean::Test::TestCase
|
|
45
42
|
}.merge(options)
|
46
43
|
@flag = GLI::Flag.new(names,@options)
|
47
44
|
@cli_option = @flag
|
48
|
-
end
|
49
45
|
end
|
50
46
|
|
51
|
-
def
|
52
|
-
lambda {
|
47
|
+
def assert_attributes_set(override={})
|
53
48
|
expected = @options.merge(override)
|
54
49
|
assert_equal(expected[:desc],@flag.description)
|
55
50
|
assert_equal(expected[:long_desc],@flag.long_description)
|
@@ -57,6 +52,5 @@ class TC_testFlag < Clean::Test::TestCase
|
|
57
52
|
assert_equal(expected[:safe_default_value],@flag.safe_default_value)
|
58
53
|
assert_equal(expected[:must_match],@flag.must_match)
|
59
54
|
assert_equal(expected[:type],@flag.type)
|
60
|
-
}
|
61
55
|
end
|
62
56
|
end
|
@@ -1,18 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# and compatibility
|
4
|
-
unless File.respond_to? :realpath
|
5
|
-
class File
|
6
|
-
def self.realpath path
|
7
|
-
return realpath(File.readlink(path)) if symlink?(path)
|
8
|
-
path
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
require_relative "test_helper"
|
2
|
+
require_relative "support/fake_std_out"
|
12
3
|
|
13
|
-
|
14
|
-
|
15
|
-
class TC_testGLI < Clean::Test::TestCase
|
4
|
+
class GLITest < MiniTest::Test
|
16
5
|
include TestHelper
|
17
6
|
|
18
7
|
def setup
|
@@ -24,7 +13,7 @@ class TC_testGLI < Clean::Test::TestCase
|
|
24
13
|
$stderr = @fake_stderr
|
25
14
|
@app = CLIApp.new
|
26
15
|
|
27
|
-
@config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/new_config.
|
16
|
+
@config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/new_config.yml')
|
28
17
|
@gli_debug = ENV['GLI_DEBUG']
|
29
18
|
@app.error_device=@fake_stderr
|
30
19
|
ENV.delete('GLI_DEBUG')
|
@@ -141,7 +130,7 @@ class TC_testGLI < Clean::Test::TestCase
|
|
141
130
|
def test_init_from_config
|
142
131
|
failure = nil
|
143
132
|
@app.reset
|
144
|
-
@app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/
|
133
|
+
@app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/gli_test_config.yml'))
|
145
134
|
@app.flag :f
|
146
135
|
@app.switch :s
|
147
136
|
@app.flag :g
|
@@ -175,7 +164,7 @@ class TC_testGLI < Clean::Test::TestCase
|
|
175
164
|
def test_command_line_overrides_config
|
176
165
|
failure = nil
|
177
166
|
@app.reset
|
178
|
-
@app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/
|
167
|
+
@app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/gli_test_config.yml'))
|
179
168
|
@app.flag :f
|
180
169
|
@app.switch :s
|
181
170
|
@app.flag :g
|
@@ -207,7 +196,7 @@ class TC_testGLI < Clean::Test::TestCase
|
|
207
196
|
end
|
208
197
|
|
209
198
|
def test_no_overwrite_config
|
210
|
-
config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/
|
199
|
+
config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/gli_test_config.yml')
|
211
200
|
config_file_contents = File.read(config_file)
|
212
201
|
@app.reset
|
213
202
|
@app.config_file(config_file)
|
@@ -680,7 +669,11 @@ class TC_testGLI < Clean::Test::TestCase
|
|
680
669
|
end
|
681
670
|
end
|
682
671
|
|
683
|
-
|
672
|
+
begin
|
673
|
+
@app.run(['multiply', '--help'])
|
674
|
+
rescue GLI::CustomExit
|
675
|
+
assert false, "Expected no exception"
|
676
|
+
end
|
684
677
|
end
|
685
678
|
|
686
679
|
class ConvertMe
|
@@ -810,38 +803,26 @@ class TC_testGLI < Clean::Test::TestCase
|
|
810
803
|
do_test_switch_create_compact(object)
|
811
804
|
end
|
812
805
|
|
813
|
-
def some_descriptions
|
814
|
-
lambda {
|
815
|
-
@description = 'this is a description'
|
816
|
-
@long_description = 'this is a very long description'
|
817
|
-
}
|
818
|
-
end
|
819
|
-
|
820
|
-
def assert_switch_was_made(object,switch)
|
821
|
-
lambda {
|
822
|
-
assert object.switches[switch]
|
823
|
-
assert_equal @description,object.switches[switch].description,"For switch #{switch}"
|
824
|
-
assert_equal @long_description,object.switches[switch].long_description,"For switch #{switch}"
|
825
|
-
assert(object.usage != nil) if object.respond_to? :usage
|
826
|
-
}
|
827
|
-
end
|
828
|
-
|
829
806
|
def do_test_switch_create_classic(object)
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
807
|
+
@description = 'this is a description'
|
808
|
+
@long_description = 'this is a very long description'
|
809
|
+
object.desc @description
|
810
|
+
object.long_desc @long_description
|
811
|
+
object.switch :f
|
812
|
+
assert object.switches[:f]
|
813
|
+
assert_equal @description,object.switches[:f].description,"For switch #{:f}"
|
814
|
+
assert_equal @long_description,object.switches[:f].long_description,"For switch #{:f}"
|
815
|
+
assert(object.usage != nil) if object.respond_to? :usage
|
837
816
|
end
|
838
817
|
|
839
818
|
def do_test_switch_create_compact(object)
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
819
|
+
@description = 'this is a description'
|
820
|
+
@long_description = 'this is a very long description'
|
821
|
+
object.switch :g, :desc => @description, :long_desc => @long_description
|
822
|
+
assert object.switches[:g]
|
823
|
+
assert_equal @description,object.switches[:g].description,"For switch #{:g}"
|
824
|
+
assert_equal @long_description,object.switches[:g].long_description,"For switch #{:g}"
|
825
|
+
assert(object.usage != nil) if object.respond_to? :usage
|
845
826
|
end
|
846
827
|
|
847
828
|
def do_test_switch_create_twice(object)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
78
|
-
|
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
|
-
|
91
|
-
|
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
|
-
|
105
|
-
|
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
|
-
|
146
|
-
|
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
|
-
|
161
|
-
|
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
|
-
|
198
|
-
|
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
|
-
|
224
|
-
|
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
|
-
|
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
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
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,
|
285
|
-
[any_desc.strip,
|
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
|
-
|
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
|
-
|
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
|
-
|
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 =
|
321
|
+
command_name = ["new","edit","delete","create","update"].sample
|
381
322
|
while @command_names_used.include?(command_name)
|
382
|
-
command_name =
|
323
|
+
command_name = ["new","edit","delete","create","update"].sample
|
383
324
|
end
|
384
325
|
@command_names_used << command_name
|
385
326
|
command_name
|