escort 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +8 -0
- data/README.md +365 -14
- data/TODO.md +157 -44
- data/escort.gemspec +1 -0
- data/examples/{1_1_basic.rb → attic/1_1_basic.rb} +0 -0
- data/examples/{1_2_basic_requires_arguments.rb → attic/1_2_basic_requires_arguments.rb} +0 -0
- data/examples/{2_2_command.rb → attic/2_2_command.rb} +0 -0
- data/examples/{2_2_command_requires_arguments.rb → attic/2_2_command_requires_arguments.rb} +0 -0
- data/examples/{2_3_nested_commands.rb → attic/2_3_nested_commands.rb} +0 -0
- data/examples/{3_validations.rb → attic/3_validations.rb} +0 -0
- data/examples/{4_1_config_file.rb → attic/4_1_config_file.rb} +0 -0
- data/examples/{argument_handling → attic/argument_handling}/basic.rb +0 -0
- data/examples/{argument_handling → attic/argument_handling}/basic_command.rb +0 -0
- data/examples/{argument_handling → attic/argument_handling}/no_arguments.rb +0 -0
- data/examples/{argument_handling → attic/argument_handling}/no_arguments_command.rb +0 -0
- data/examples/{command_aliases → attic/command_aliases}/app.rb +0 -0
- data/examples/{config_file → attic/config_file}/.apprc2 +0 -0
- data/examples/{config_file → attic/config_file}/app.rb +0 -0
- data/examples/{config_file → attic/config_file}/sub_commands.rb +0 -0
- data/examples/{default_command → attic/default_command}/app.rb +0 -0
- data/examples/{sub_commands → attic/sub_commands}/app.rb +0 -0
- data/examples/{validation_basic → attic/validation_basic}/app.rb +0 -0
- data/examples/basic +10 -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/command +19 -0
- data/examples/commands/example_command.rb +13 -0
- data/lib/escort/action_command/base.rb +4 -0
- data/lib/escort/app.rb +33 -11
- data/lib/escort/formatter/borderless_table.rb +4 -0
- data/lib/escort/formatter/command.rb +87 -0
- data/lib/escort/formatter/commands.rb +36 -0
- data/lib/escort/formatter/default_help_formatter.rb +68 -73
- data/lib/escort/formatter/global_command.rb +17 -0
- data/lib/escort/formatter/option.rb +138 -0
- data/lib/escort/formatter/options.rb +17 -3
- data/lib/escort/formatter/shell_command_executor.rb +49 -0
- data/lib/escort/formatter/terminal.rb +17 -9
- data/lib/escort/formatter/terminal_formatter.rb +6 -0
- data/lib/escort/logger.rb +4 -4
- data/lib/escort/option_dependency_validator.rb +83 -0
- data/lib/escort/option_parser.rb +11 -1
- data/lib/escort/setup/configuration/reader.rb +0 -2
- data/lib/escort/setup/configuration/writer.rb +0 -2
- data/lib/escort/setup/dsl/command.rb +2 -7
- data/lib/escort/setup/dsl/global.rb +2 -9
- data/lib/escort/setup/dsl/options.rb +56 -0
- data/lib/escort/setup_accessor.rb +23 -6
- data/lib/escort/trollop.rb +4 -3
- data/lib/escort/validator.rb +4 -1
- data/lib/escort/version.rb +1 -1
- data/lib/escort.rb +8 -1
- 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 +9 -21
- data/spec/integration/basic_options_with_multi_spec.rb +30 -0
- data/spec/integration/basic_spec.rb +5 -6
- data/spec/integration/basic_validations_spec.rb +77 -0
- data/spec/integration/basic_with_arguments_spec.rb +33 -0
- data/spec/integration/basic_with_text_fields_spec.rb +21 -0
- data/spec/lib/escort/formatter/command_spec.rb +238 -0
- data/spec/lib/escort/formatter/global_command_spec.rb +50 -0
- data/spec/lib/escort/formatter/option_spec.rb +300 -0
- data/spec/lib/escort/formatter/shell_command_executor_spec.rb +59 -0
- data/spec/lib/escort/formatter/string_splitter_spec.rb +12 -0
- data/spec/lib/escort/formatter/terminal_spec.rb +19 -0
- data/spec/lib/escort/setup_accessor_spec.rb +1 -0
- data/spec/spec_helper.rb +9 -3
- data/spec/support/integration_helpers.rb +2 -0
- data/spec/{helpers/execute_action_matcher.rb → support/matchers/execute_action_for_command_matcher.rb} +3 -3
- 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 +86 -28
- data/examples/basic/app.rb +0 -16
- data/lib/escort/formatter/common.rb +0 -58
- data/spec/helpers/exit_with_code_matcher.rb +0 -21
- data/spec/helpers/give_option_to_action_with_value_matcher.rb +0 -22
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'escort'
|
2
|
+
|
3
|
+
|
4
|
+
Dir[File.join(File.dirname(__FILE__), 'support', '**', "*.rb").to_s].each {|file| require file }
|
5
|
+
|
2
6
|
#helpers
|
3
|
-
require 'helpers/exit_with_code_matcher'
|
4
|
-
require 'helpers/execute_action_matcher'
|
5
|
-
require 'helpers/give_option_to_action_with_value_matcher'
|
7
|
+
#require 'helpers/exit_with_code_matcher'
|
8
|
+
#require 'helpers/execute_action_matcher'
|
9
|
+
#require 'helpers/give_option_to_action_with_value_matcher'
|
6
10
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
11
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
12
|
# Require this file using `require "spec_helper"` to ensure that it is only
|
@@ -14,6 +18,8 @@ RSpec.configure do |config|
|
|
14
18
|
config.run_all_when_everything_filtered = true
|
15
19
|
config.filter_run :focus
|
16
20
|
|
21
|
+
config.include IntegrationHelpers, :integration => true
|
22
|
+
|
17
23
|
# Run specs in random order to surface order dependencies. If you find an
|
18
24
|
# order dependency and want to debug it, you can fix the order by providing
|
19
25
|
# the seed, which is printed after each run.
|
@@ -1,14 +1,14 @@
|
|
1
|
-
RSpec::Matchers.define :
|
1
|
+
RSpec::Matchers.define :execute_action_for_command do |result, command_name|
|
2
2
|
match do |block|
|
3
3
|
begin
|
4
4
|
block.call
|
5
5
|
rescue SystemExit => e
|
6
6
|
end
|
7
|
-
result
|
7
|
+
result[:command_name] == command_name
|
8
8
|
end
|
9
9
|
|
10
10
|
failure_message_for_should do |block|
|
11
|
-
"'#{command_name}' action should have been executed as a result of block, but instead '#{result
|
11
|
+
"'#{command_name}' action should have been executed as a result of block, but instead '#{result[:command_name]}' was executed"
|
12
12
|
end
|
13
13
|
|
14
14
|
failure_message_for_should_not do |block|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
RSpec::Matchers.define :execute_action_with_arguments do |result, expected_arguments|
|
2
|
+
match do |block|
|
3
|
+
begin
|
4
|
+
block.call
|
5
|
+
rescue SystemExit => e
|
6
|
+
end
|
7
|
+
successful_match?(result, expected_arguments)
|
8
|
+
end
|
9
|
+
|
10
|
+
def successful_match?(result, expected_arguments)
|
11
|
+
result[:arguments] == expected_arguments
|
12
|
+
end
|
13
|
+
|
14
|
+
failure_message_for_should do |block|
|
15
|
+
"'#{expected_arguments}' should have been passed to action, but we got '#{result[:arguments]}'"
|
16
|
+
end
|
17
|
+
|
18
|
+
failure_message_for_should_not do |block|
|
19
|
+
"'#{expected_arguments}' should not have been passed to action"
|
20
|
+
end
|
21
|
+
|
22
|
+
description do
|
23
|
+
"'#{expected_arguments}' should have been passed to action"
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define :execute_action_with_options do |result, expected_options|
|
2
|
+
match do |block|
|
3
|
+
begin
|
4
|
+
block.call
|
5
|
+
rescue SystemExit => e
|
6
|
+
end
|
7
|
+
successful_match?(result, expected_options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def successful_match?(result, expected_options)
|
11
|
+
options = result[:command_options]
|
12
|
+
expected_options.keys.each do |key|
|
13
|
+
return false unless options[key] == expected_options[key]
|
14
|
+
end
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
failure_message_for_should do |block|
|
19
|
+
"'#{expected_options}' should have been passed to action, but we got '#{result[:command_options]}'"
|
20
|
+
end
|
21
|
+
|
22
|
+
failure_message_for_should_not do |block|
|
23
|
+
"'#{expected_options}' should not have been passed to action"
|
24
|
+
end
|
25
|
+
|
26
|
+
description do
|
27
|
+
"'#{expected_options}' should have been passed to action"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define :exit_with_code do |*expected_code|
|
2
|
+
actual = nil
|
3
|
+
match do |block|
|
4
|
+
begin
|
5
|
+
block.call
|
6
|
+
rescue SystemExit => e
|
7
|
+
actual = e.status
|
8
|
+
end
|
9
|
+
has_expected_exit_code?(actual, *expected_code)
|
10
|
+
#actual && actual == expected_code
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_expected_exit_code?(actual, *expected_code)
|
14
|
+
expected_code.each do |code|
|
15
|
+
return true if actual && actual == code
|
16
|
+
end
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
failure_message_for_should do |block|
|
21
|
+
"expected block to call exit(#{expected_code}) but exit #{actual.nil? ? "not called" : "(#{actual}) was called"}"
|
22
|
+
end
|
23
|
+
failure_message_for_should_not do |block|
|
24
|
+
"expected block not to call exit(#{expected_code})"
|
25
|
+
end
|
26
|
+
description do
|
27
|
+
"expect block to call exit(#{expected_code})"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
shared_context "integration test setup", :integration => true do
|
2
|
+
let(:result) { {} }
|
3
|
+
|
4
|
+
before do
|
5
|
+
empty_argv
|
6
|
+
#$stderr = StringIO.new
|
7
|
+
#$stdout = StringIO.new
|
8
|
+
$stdin = StringIO.new
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
$stderr = STDERR
|
13
|
+
$stdout = STDOUT
|
14
|
+
$stdin = STDIN
|
15
|
+
end
|
16
|
+
|
17
|
+
module Escort
|
18
|
+
class IntegrationTestCommand < ::Escort::ActionCommand::Base
|
19
|
+
def execute(result)
|
20
|
+
result[:command_name] = command_name
|
21
|
+
result[:command_options] = command_options
|
22
|
+
result[:options] = options
|
23
|
+
result[:arguments] = arguments
|
24
|
+
result[:config] = config if config
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def empty_argv
|
30
|
+
while !ARGV.empty? do
|
31
|
+
ARGV.delete_at(0)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Skorkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: travis-lint
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Writing even complex command-line apps should be quick, easy and fun.
|
56
70
|
Escort takes the excellent Trollop option parser and adds a whole bunch of awesome
|
57
71
|
features to produce a library you will always want to turn to when a 'quick script'
|
@@ -66,31 +80,42 @@ files:
|
|
66
80
|
- .irbrc
|
67
81
|
- .rspec
|
68
82
|
- .rvmrc
|
83
|
+
- .travis.yml
|
69
84
|
- Gemfile
|
70
85
|
- LICENSE.txt
|
71
86
|
- README.md
|
72
87
|
- Rakefile
|
73
88
|
- TODO.md
|
74
89
|
- escort.gemspec
|
75
|
-
- examples/1_1_basic.rb
|
76
|
-
- examples/1_2_basic_requires_arguments.rb
|
77
|
-
- examples/2_2_command.rb
|
78
|
-
- examples/2_2_command_requires_arguments.rb
|
79
|
-
- examples/2_3_nested_commands.rb
|
80
|
-
- examples/3_validations.rb
|
81
|
-
- examples/4_1_config_file.rb
|
82
|
-
- examples/argument_handling/basic.rb
|
83
|
-
- examples/argument_handling/basic_command.rb
|
84
|
-
- examples/argument_handling/no_arguments.rb
|
85
|
-
- examples/argument_handling/no_arguments_command.rb
|
86
|
-
- examples/
|
87
|
-
- examples/
|
88
|
-
- examples/config_file
|
89
|
-
- examples/config_file/
|
90
|
-
- examples/
|
91
|
-
- examples/
|
92
|
-
- examples/
|
93
|
-
- examples/
|
90
|
+
- examples/attic/1_1_basic.rb
|
91
|
+
- examples/attic/1_2_basic_requires_arguments.rb
|
92
|
+
- examples/attic/2_2_command.rb
|
93
|
+
- examples/attic/2_2_command_requires_arguments.rb
|
94
|
+
- examples/attic/2_3_nested_commands.rb
|
95
|
+
- examples/attic/3_validations.rb
|
96
|
+
- examples/attic/4_1_config_file.rb
|
97
|
+
- examples/attic/argument_handling/basic.rb
|
98
|
+
- examples/attic/argument_handling/basic_command.rb
|
99
|
+
- examples/attic/argument_handling/no_arguments.rb
|
100
|
+
- examples/attic/argument_handling/no_arguments_command.rb
|
101
|
+
- examples/attic/command_aliases/app.rb
|
102
|
+
- examples/attic/config_file/.apprc2
|
103
|
+
- examples/attic/config_file/app.rb
|
104
|
+
- examples/attic/config_file/sub_commands.rb
|
105
|
+
- examples/attic/default_command/app.rb
|
106
|
+
- examples/attic/sub_commands/app.rb
|
107
|
+
- examples/attic/validation_basic/app.rb
|
108
|
+
- examples/basic
|
109
|
+
- examples/basic_conflicts
|
110
|
+
- examples/basic_depends_on
|
111
|
+
- examples/basic_flags
|
112
|
+
- examples/basic_options
|
113
|
+
- examples/basic_options_multi
|
114
|
+
- examples/basic_require_arguments
|
115
|
+
- examples/basic_texts
|
116
|
+
- examples/basic_validations
|
117
|
+
- examples/command
|
118
|
+
- examples/commands/example_command.rb
|
94
119
|
- lib/escort.rb
|
95
120
|
- lib/escort/action_command/base.rb
|
96
121
|
- lib/escort/action_command/escort_utility_command.rb
|
@@ -99,14 +124,19 @@ files:
|
|
99
124
|
- lib/escort/auto_options.rb
|
100
125
|
- lib/escort/error/error.rb
|
101
126
|
- lib/escort/formatter/borderless_table.rb
|
102
|
-
- lib/escort/formatter/
|
127
|
+
- lib/escort/formatter/command.rb
|
128
|
+
- lib/escort/formatter/commands.rb
|
103
129
|
- lib/escort/formatter/default_help_formatter.rb
|
130
|
+
- lib/escort/formatter/global_command.rb
|
131
|
+
- lib/escort/formatter/option.rb
|
104
132
|
- lib/escort/formatter/options.rb
|
133
|
+
- lib/escort/formatter/shell_command_executor.rb
|
105
134
|
- lib/escort/formatter/string_splitter.rb
|
106
135
|
- lib/escort/formatter/terminal.rb
|
107
136
|
- lib/escort/formatter/terminal_formatter.rb
|
108
137
|
- lib/escort/global_pre_parser.rb
|
109
138
|
- lib/escort/logger.rb
|
139
|
+
- lib/escort/option_dependency_validator.rb
|
110
140
|
- lib/escort/option_parser.rb
|
111
141
|
- lib/escort/setup/configuration/generator.rb
|
112
142
|
- lib/escort/setup/configuration/instance.rb
|
@@ -127,15 +157,29 @@ files:
|
|
127
157
|
- lib/escort/utils.rb
|
128
158
|
- lib/escort/validator.rb
|
129
159
|
- lib/escort/version.rb
|
130
|
-
- spec/
|
131
|
-
- spec/
|
132
|
-
- spec/helpers/give_option_to_action_with_value_matcher.rb
|
160
|
+
- spec/integration/basic_conflicts_spec.rb
|
161
|
+
- spec/integration/basic_depends_on_spec.rb
|
133
162
|
- spec/integration/basic_options_spec.rb
|
163
|
+
- spec/integration/basic_options_with_multi_spec.rb
|
134
164
|
- spec/integration/basic_spec.rb
|
165
|
+
- spec/integration/basic_validations_spec.rb
|
166
|
+
- spec/integration/basic_with_arguments_spec.rb
|
167
|
+
- spec/integration/basic_with_text_fields_spec.rb
|
168
|
+
- spec/lib/escort/formatter/command_spec.rb
|
169
|
+
- spec/lib/escort/formatter/global_command_spec.rb
|
170
|
+
- spec/lib/escort/formatter/option_spec.rb
|
171
|
+
- spec/lib/escort/formatter/shell_command_executor_spec.rb
|
135
172
|
- spec/lib/escort/formatter/string_splitter_spec.rb
|
173
|
+
- spec/lib/escort/formatter/terminal_spec.rb
|
136
174
|
- spec/lib/escort/setup_accessor_spec.rb
|
137
175
|
- spec/lib/escort/utils_spec.rb
|
138
176
|
- spec/spec_helper.rb
|
177
|
+
- spec/support/integration_helpers.rb
|
178
|
+
- spec/support/matchers/execute_action_for_command_matcher.rb
|
179
|
+
- spec/support/matchers/execute_action_with_arguments_matcher.rb
|
180
|
+
- spec/support/matchers/execute_action_with_options_matcher.rb
|
181
|
+
- spec/support/matchers/exit_with_code_matcher.rb
|
182
|
+
- spec/support/shared_contexts/integration_setup.rb
|
139
183
|
homepage: https://github.com/skorks/escort
|
140
184
|
licenses: []
|
141
185
|
metadata: {}
|
@@ -161,12 +205,26 @@ specification_version: 4
|
|
161
205
|
summary: A library that makes building command line apps in ruby so easy, you'll feel
|
162
206
|
like an expert is guiding you through it
|
163
207
|
test_files:
|
164
|
-
- spec/
|
165
|
-
- spec/
|
166
|
-
- spec/helpers/give_option_to_action_with_value_matcher.rb
|
208
|
+
- spec/integration/basic_conflicts_spec.rb
|
209
|
+
- spec/integration/basic_depends_on_spec.rb
|
167
210
|
- spec/integration/basic_options_spec.rb
|
211
|
+
- spec/integration/basic_options_with_multi_spec.rb
|
168
212
|
- spec/integration/basic_spec.rb
|
213
|
+
- spec/integration/basic_validations_spec.rb
|
214
|
+
- spec/integration/basic_with_arguments_spec.rb
|
215
|
+
- spec/integration/basic_with_text_fields_spec.rb
|
216
|
+
- spec/lib/escort/formatter/command_spec.rb
|
217
|
+
- spec/lib/escort/formatter/global_command_spec.rb
|
218
|
+
- spec/lib/escort/formatter/option_spec.rb
|
219
|
+
- spec/lib/escort/formatter/shell_command_executor_spec.rb
|
169
220
|
- spec/lib/escort/formatter/string_splitter_spec.rb
|
221
|
+
- spec/lib/escort/formatter/terminal_spec.rb
|
170
222
|
- spec/lib/escort/setup_accessor_spec.rb
|
171
223
|
- spec/lib/escort/utils_spec.rb
|
172
224
|
- spec/spec_helper.rb
|
225
|
+
- spec/support/integration_helpers.rb
|
226
|
+
- spec/support/matchers/execute_action_for_command_matcher.rb
|
227
|
+
- spec/support/matchers/execute_action_with_arguments_matcher.rb
|
228
|
+
- spec/support/matchers/execute_action_with_options_matcher.rb
|
229
|
+
- spec/support/matchers/exit_with_code_matcher.rb
|
230
|
+
- spec/support/shared_contexts/integration_setup.rb
|
data/examples/basic/app.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "..", "lib", "escort"))
|
3
|
-
|
4
|
-
Escort::App.create do |app|
|
5
|
-
#app.version "0.2.4"
|
6
|
-
#app.format_help_with(:default_formatter)
|
7
|
-
|
8
|
-
app.options do
|
9
|
-
opt :global_option, "Global option", :short => '-g', :long => '--global', :type => :string, :default => "global"
|
10
|
-
opt :multi_option, "Option that can be specified multiple times alksjdfh lakjdfh adf alksdfh alkdfjh alsdfjhaskdjfh alsdkfjh alksfdjh akdfjh alkdsjf alksdjfh alksdfjh asdfjklh aslkdfhj aslkdfjh adfjkhl", :short => '-m', :long => '--multi', :type => :string, :multi => true
|
11
|
-
end
|
12
|
-
|
13
|
-
app.action do |options, arguments|
|
14
|
-
puts "Action for my_command\nglobal options: #{options} \narguments: #{arguments}"
|
15
|
-
end
|
16
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module Escort
|
2
|
-
module Formatter
|
3
|
-
module Common
|
4
|
-
def option_output_strings(parser)
|
5
|
-
options = {}
|
6
|
-
parser.specs.each do |name, spec|
|
7
|
-
options[name] = "--#{spec[:long]}" +
|
8
|
-
(spec[:type] == :flag && spec[:default] ? ", --no-#{spec[:long]}" : "") +
|
9
|
-
(spec[:short] && spec[:short] != :none ? ", -#{spec[:short]}" : "") +
|
10
|
-
case spec[:type]
|
11
|
-
when :flag; ""
|
12
|
-
when :int; " <i>"
|
13
|
-
when :ints; " <i+>"
|
14
|
-
when :string; " <s>"
|
15
|
-
when :strings; " <s+>"
|
16
|
-
when :float; " <f>"
|
17
|
-
when :floats; " <f+>"
|
18
|
-
when :io; " <filename/uri>"
|
19
|
-
when :ios; " <filename/uri+>"
|
20
|
-
when :date; " <date>"
|
21
|
-
when :dates; " <date+>"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
parser.order.each do |what, opt|
|
26
|
-
if what == :text
|
27
|
-
next
|
28
|
-
end
|
29
|
-
spec = parser.specs[opt]
|
30
|
-
desc = spec[:desc] + begin
|
31
|
-
default_s = case spec[:default]
|
32
|
-
when $stdout; "<stdout>"
|
33
|
-
when $stdin; "<stdin>"
|
34
|
-
when $stderr; "<stderr>"
|
35
|
-
when Array
|
36
|
-
spec[:default].join(", ")
|
37
|
-
else
|
38
|
-
spec[:default].to_s
|
39
|
-
end
|
40
|
-
|
41
|
-
if spec[:default]
|
42
|
-
if spec[:desc] =~ /\.$/
|
43
|
-
" (Default: #{default_s})"
|
44
|
-
else
|
45
|
-
" (default: #{default_s})"
|
46
|
-
end
|
47
|
-
else
|
48
|
-
""
|
49
|
-
end
|
50
|
-
end
|
51
|
-
options[opt] = {:string => options[opt]}
|
52
|
-
options[opt][:desc] = desc
|
53
|
-
end
|
54
|
-
options
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :exit_with_code do |exp_code|
|
2
|
-
actual = nil
|
3
|
-
match do |block|
|
4
|
-
begin
|
5
|
-
block.call
|
6
|
-
rescue SystemExit => e
|
7
|
-
actual = e.status
|
8
|
-
end
|
9
|
-
actual and actual == exp_code
|
10
|
-
end
|
11
|
-
failure_message_for_should do |block|
|
12
|
-
"expected block to call exit(#{exp_code}) but exit" +
|
13
|
-
(actual.nil? ? " not called" : "(#{actual}) was called")
|
14
|
-
end
|
15
|
-
failure_message_for_should_not do |block|
|
16
|
-
"expected block not to call exit(#{exp_code})"
|
17
|
-
end
|
18
|
-
description do
|
19
|
-
"expect block to call exit(#{exp_code})"
|
20
|
-
end
|
21
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :give_option_to_action_with_value do |option_name, expected_value, result|
|
2
|
-
match do |block|
|
3
|
-
begin
|
4
|
-
block.call
|
5
|
-
rescue SystemExit => e
|
6
|
-
end
|
7
|
-
options = result[1] || {}
|
8
|
-
options.keys.include?(option_name) && options[option_name] == expected_value
|
9
|
-
end
|
10
|
-
|
11
|
-
failure_message_for_should do |block|
|
12
|
-
"'#{option_name}' should have been passed to action with value '#{expected_value}', but instead we got '#{(result[1] || {})[option_name]}'"
|
13
|
-
end
|
14
|
-
|
15
|
-
failure_message_for_should_not do |block|
|
16
|
-
"'#{option_name}' should not have been passed to action with value '#{expected_value}'"
|
17
|
-
end
|
18
|
-
|
19
|
-
description do
|
20
|
-
"'#{option_name}' should have been passed to action with value '#{expected_value}'"
|
21
|
-
end
|
22
|
-
end
|