cri 2.14.0 → 2.15.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.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +41 -13
- data/Gemfile +0 -1
- data/Gemfile.lock +1 -3
- data/NEWS.md +6 -0
- data/README.md +6 -0
- data/Rakefile +2 -6
- data/lib/cri.rb +1 -1
- data/lib/cri/argument_list.rb +9 -4
- data/lib/cri/command.rb +14 -14
- data/lib/cri/command_dsl.rb +9 -6
- data/lib/cri/param_definition.rb +3 -1
- data/lib/cri/{option_parser.rb → parser.rb} +3 -55
- data/lib/cri/string_formatter.rb +5 -5
- data/lib/cri/version.rb +1 -1
- data/test/test_argument_list.rb +13 -3
- data/test/test_command_dsl.rb +26 -0
- data/test/{test_option_parser.rb → test_parser.rb} +58 -58
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 146523ca2691641e1484d4765e730e990d70d7d32b2ab5aaf9e6911e089fab8b
|
|
4
|
+
data.tar.gz: 9d77fc29f799f5a18d13089bd41c2c309bebfaa6620b63f07be57b354c5e33aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ccb3ac10e23d38eda1f739f6b33ac68540d9ab9895ac66870fba15f4b7c6ae2ff159c706627996bc8ee9f566fed0068a11b708df2747df77400070ad48ed0163
|
|
7
|
+
data.tar.gz: 0464fc3a9942c35b7f6477af69495a716d06abd6bf5c2197d955342b2d77f001b3a52b795ebe4b2a186f45eaea3cb5b13fe22458fed986706dae756a1092fd18
|
data/CODE_OF_CONDUCT.md
CHANGED
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## Our Pledge
|
|
4
4
|
|
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
|
6
11
|
|
|
7
12
|
## Our Standards
|
|
8
13
|
|
|
9
|
-
Examples of behavior that contributes to creating a positive environment
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
10
16
|
|
|
11
17
|
* Using welcoming and inclusive language
|
|
12
18
|
* Being respectful of differing viewpoints and experiences
|
|
@@ -16,31 +22,53 @@ Examples of behavior that contributes to creating a positive environment include
|
|
|
16
22
|
|
|
17
23
|
Examples of unacceptable behavior by participants include:
|
|
18
24
|
|
|
19
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
20
27
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
21
28
|
* Public or private harassment
|
|
22
|
-
* Publishing others' private information, such as a physical or electronic
|
|
23
|
-
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
24
33
|
|
|
25
34
|
## Our Responsibilities
|
|
26
35
|
|
|
27
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
28
39
|
|
|
29
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
30
45
|
|
|
31
46
|
## Scope
|
|
32
47
|
|
|
33
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
34
54
|
|
|
35
55
|
## Enforcement
|
|
36
56
|
|
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at denis+coc@denis.ws. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
38
63
|
|
|
39
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
40
67
|
|
|
41
68
|
## Attribution
|
|
42
69
|
|
|
43
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
|
72
|
+
|
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
|
44
74
|
|
|
45
|
-
[homepage]: http://contributor-covenant.org
|
|
46
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
cri (2.
|
|
4
|
+
cri (2.15.0)
|
|
5
5
|
colored (~> 1.2)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
asciidoctor (1.5.7.1)
|
|
11
10
|
ast (2.4.0)
|
|
12
11
|
colored (1.2)
|
|
13
12
|
coveralls (0.8.22)
|
|
@@ -51,7 +50,6 @@ PLATFORMS
|
|
|
51
50
|
ruby
|
|
52
51
|
|
|
53
52
|
DEPENDENCIES
|
|
54
|
-
asciidoctor
|
|
55
53
|
bundler (~> 1.6)
|
|
56
54
|
coveralls
|
|
57
55
|
cri!
|
data/NEWS.md
CHANGED
data/README.md
CHANGED
|
@@ -281,6 +281,12 @@ Resetting…
|
|
|
281
281
|
|
|
282
282
|
A future version of Cri will likely make `#no_params` the default behavior.
|
|
283
283
|
|
|
284
|
+
As with options, parameter definitions take `transform:`, which can be used for transforming and validating arguments:
|
|
285
|
+
|
|
286
|
+
```ruby
|
|
287
|
+
param :port, transform: method(:Integer)
|
|
288
|
+
```
|
|
289
|
+
|
|
284
290
|
(*Why the distinction between argument and parameter?* A parameter is a name, e.g. `filename`, while an argument is a value for a parameter, e.g. `kitten.jpg`.)
|
|
285
291
|
|
|
286
292
|
### The run block
|
data/Rakefile
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# encoing: utf-8
|
|
4
|
-
|
|
5
3
|
require 'rake/testtask'
|
|
6
4
|
require 'rubocop/rake_task'
|
|
7
5
|
require 'yard'
|
|
@@ -10,7 +8,7 @@ YARD::Rake::YardocTask.new(:doc) do |yard|
|
|
|
10
8
|
yard.files = Dir['lib/**/*.rb']
|
|
11
9
|
yard.options = [
|
|
12
10
|
'--markup', 'markdown',
|
|
13
|
-
'--readme', 'README.
|
|
11
|
+
'--readme', 'README.md',
|
|
14
12
|
'--files', 'NEWS.md,LICENSE',
|
|
15
13
|
'--output-dir', 'doc/yardoc'
|
|
16
14
|
]
|
|
@@ -21,9 +19,7 @@ Rake::TestTask.new(:test_unit) do |t|
|
|
|
21
19
|
t.libs << 'test'
|
|
22
20
|
end
|
|
23
21
|
|
|
24
|
-
RuboCop::RakeTask.new(:test_style)
|
|
25
|
-
task.options = %w[--display-cop-names --format simple]
|
|
26
|
-
end
|
|
22
|
+
RuboCop::RakeTask.new(:test_style)
|
|
27
23
|
|
|
28
24
|
task test: %i[test_unit test_style]
|
|
29
25
|
|
data/lib/cri.rb
CHANGED
|
@@ -30,6 +30,6 @@ require_relative 'cri/command_dsl'
|
|
|
30
30
|
require_relative 'cri/command_runner'
|
|
31
31
|
require_relative 'cri/help_renderer'
|
|
32
32
|
require_relative 'cri/option_definition'
|
|
33
|
-
require_relative 'cri/
|
|
33
|
+
require_relative 'cri/parser'
|
|
34
34
|
require_relative 'cri/param_definition'
|
|
35
35
|
require_relative 'cri/platform'
|
data/lib/cri/argument_list.rb
CHANGED
|
@@ -54,20 +54,25 @@ module Cri
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def load
|
|
57
|
-
@arguments_array =
|
|
57
|
+
@arguments_array = []
|
|
58
58
|
@arguments_hash = {}
|
|
59
59
|
|
|
60
|
+
arguments_array = @raw_arguments.reject { |a| a == '--' }.freeze
|
|
61
|
+
|
|
60
62
|
if !@explicitly_no_params && @param_defns.empty?
|
|
61
63
|
# No parameters defined; ignore
|
|
64
|
+
@arguments_array = arguments_array
|
|
62
65
|
return
|
|
63
66
|
end
|
|
64
67
|
|
|
65
|
-
if
|
|
66
|
-
raise ArgumentCountMismatchError.new(@param_defns.size,
|
|
68
|
+
if arguments_array.size != @param_defns.size
|
|
69
|
+
raise ArgumentCountMismatchError.new(@param_defns.size, arguments_array.size)
|
|
67
70
|
end
|
|
68
71
|
|
|
69
|
-
|
|
72
|
+
arguments_array.zip(@param_defns).each do |(arg, param_defn)|
|
|
73
|
+
arg = param_defn.transform ? param_defn.transform.call(arg) : arg
|
|
70
74
|
@arguments_hash[param_defn.name.to_sym] = arg
|
|
75
|
+
@arguments_array << arg
|
|
71
76
|
end
|
|
72
77
|
end
|
|
73
78
|
end
|
data/lib/cri/command.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Cri
|
|
|
9
9
|
# command, is found.
|
|
10
10
|
#
|
|
11
11
|
# @api private
|
|
12
|
-
class
|
|
12
|
+
class ParserPartitioningDelegate
|
|
13
13
|
# Returns the last parsed argument, which, in this case, will be the
|
|
14
14
|
# first argument, which will be either nil or the command name.
|
|
15
15
|
#
|
|
@@ -18,25 +18,25 @@ module Cri
|
|
|
18
18
|
|
|
19
19
|
# Called when an option is parsed.
|
|
20
20
|
#
|
|
21
|
-
# @param [Symbol]
|
|
21
|
+
# @param [Symbol] _key The option key (derived from the long format)
|
|
22
22
|
#
|
|
23
|
-
# @param
|
|
23
|
+
# @param _value The option value
|
|
24
24
|
#
|
|
25
|
-
# @param [Cri::
|
|
25
|
+
# @param [Cri::Parser] _parser The option parser
|
|
26
26
|
#
|
|
27
27
|
# @return [void]
|
|
28
|
-
def option_added(_key, _value,
|
|
28
|
+
def option_added(_key, _value, _parser); end
|
|
29
29
|
|
|
30
30
|
# Called when an argument is parsed.
|
|
31
31
|
#
|
|
32
32
|
# @param [String] argument The argument
|
|
33
33
|
#
|
|
34
|
-
# @param [Cri::
|
|
34
|
+
# @param [Cri::Parser] parser The option parser
|
|
35
35
|
#
|
|
36
36
|
# @return [void]
|
|
37
|
-
def argument_added(argument,
|
|
37
|
+
def argument_added(argument, parser)
|
|
38
38
|
@last_argument = argument
|
|
39
|
-
|
|
39
|
+
parser.stop
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -336,7 +336,7 @@ module Cri
|
|
|
336
336
|
global_opts = parent_opts
|
|
337
337
|
else
|
|
338
338
|
# Parse
|
|
339
|
-
parser = Cri::
|
|
339
|
+
parser = Cri::Parser.new(
|
|
340
340
|
opts_and_args,
|
|
341
341
|
global_option_definitions,
|
|
342
342
|
parameter_definitions,
|
|
@@ -395,8 +395,8 @@ module Cri
|
|
|
395
395
|
return [{}, opts_and_args.first, opts_and_args] if all_opts_as_args?
|
|
396
396
|
|
|
397
397
|
# Parse
|
|
398
|
-
delegate = Cri::Command::
|
|
399
|
-
parser = Cri::
|
|
398
|
+
delegate = Cri::Command::ParserPartitioningDelegate.new
|
|
399
|
+
parser = Cri::Parser.new(
|
|
400
400
|
opts_and_args,
|
|
401
401
|
global_option_definitions,
|
|
402
402
|
parameter_definitions,
|
|
@@ -415,13 +415,13 @@ module Cri
|
|
|
415
415
|
|
|
416
416
|
def handle_errors_while
|
|
417
417
|
yield
|
|
418
|
-
rescue Cri::
|
|
418
|
+
rescue Cri::Parser::IllegalOptionError => e
|
|
419
419
|
warn "#{name}: unrecognised option -- #{e}"
|
|
420
420
|
raise CriExitException.new(is_error: true)
|
|
421
|
-
rescue Cri::
|
|
421
|
+
rescue Cri::Parser::OptionRequiresAnArgumentError => e
|
|
422
422
|
warn "#{name}: option requires an argument -- #{e}"
|
|
423
423
|
raise CriExitException.new(is_error: true)
|
|
424
|
-
rescue Cri::
|
|
424
|
+
rescue Cri::Parser::IllegalOptionValueError => e
|
|
425
425
|
warn "#{name}: #{e.message}"
|
|
426
426
|
raise CriExitException.new(is_error: true)
|
|
427
427
|
rescue Cri::ArgumentList::ArgumentCountMismatchError => e
|
data/lib/cri/command_dsl.rb
CHANGED
|
@@ -126,7 +126,7 @@ module Cri
|
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
# Skips option parsing for the command. Allows option-like arguments to be
|
|
129
|
-
# passed in, avoiding the {Cri::
|
|
129
|
+
# passed in, avoiding the {Cri::Parser} validation.
|
|
130
130
|
#
|
|
131
131
|
# @return [void]
|
|
132
132
|
def skip_option_parsing
|
|
@@ -170,12 +170,15 @@ module Cri
|
|
|
170
170
|
# Defines a new parameter for the command.
|
|
171
171
|
#
|
|
172
172
|
# @param [Symbol] name The name of the parameter
|
|
173
|
-
def param(name)
|
|
173
|
+
def param(name, transform: nil)
|
|
174
174
|
if @command.explicitly_no_params?
|
|
175
175
|
raise AlreadySpecifiedAsNoParams.new(name, @command)
|
|
176
176
|
end
|
|
177
177
|
|
|
178
|
-
@command.parameter_definitions << Cri::ParamDefinition.new(
|
|
178
|
+
@command.parameter_definitions << Cri::ParamDefinition.new(
|
|
179
|
+
name: name,
|
|
180
|
+
transform: transform,
|
|
181
|
+
)
|
|
179
182
|
end
|
|
180
183
|
|
|
181
184
|
def no_params
|
|
@@ -205,7 +208,7 @@ module Cri
|
|
|
205
208
|
#
|
|
206
209
|
# @deprecated
|
|
207
210
|
#
|
|
208
|
-
# @see
|
|
211
|
+
# @see #option
|
|
209
212
|
def required(short, long, desc, params = {}, &block)
|
|
210
213
|
params = params.merge(argument: :required)
|
|
211
214
|
option(short, long, desc, params, &block)
|
|
@@ -228,7 +231,7 @@ module Cri
|
|
|
228
231
|
#
|
|
229
232
|
# @return [void]
|
|
230
233
|
#
|
|
231
|
-
# @see
|
|
234
|
+
# @see #option
|
|
232
235
|
def flag(short, long, desc, params = {}, &block)
|
|
233
236
|
params = params.merge(argument: :forbidden)
|
|
234
237
|
option(short, long, desc, params, &block)
|
|
@@ -254,7 +257,7 @@ module Cri
|
|
|
254
257
|
#
|
|
255
258
|
# @deprecated
|
|
256
259
|
#
|
|
257
|
-
# @see
|
|
260
|
+
# @see #option
|
|
258
261
|
def optional(short, long, desc, params = {}, &block)
|
|
259
262
|
params = params.merge(argument: :optional)
|
|
260
263
|
option(short, long, desc, params, &block)
|
data/lib/cri/param_definition.rb
CHANGED
|
@@ -1,60 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Cri
|
|
4
|
-
# Cri::
|
|
5
|
-
|
|
6
|
-
# Option definitions are hashes with the keys `:short`, `:long` and
|
|
7
|
-
# `:argument` (optionally `:description` but this is not used by the
|
|
8
|
-
# option parser, only by the help generator). `:short` is the short,
|
|
9
|
-
# one-character option, without the `-` prefix. `:long` is the long,
|
|
10
|
-
# multi-character option, without the `--` prefix. `:argument` can be
|
|
11
|
-
# :required (if an argument should be provided to the option), :optional
|
|
12
|
-
# (if an argument may be provided) or :forbidden (if an argument should
|
|
13
|
-
# not be provided).
|
|
14
|
-
#
|
|
15
|
-
# A sample array of definition hashes could look like this:
|
|
16
|
-
#
|
|
17
|
-
# [
|
|
18
|
-
# { :short => 'a', :long => 'all', :argument => :forbidden, :multiple => true },
|
|
19
|
-
# { :short => 'p', :long => 'port', :argument => :required, :multiple => false },
|
|
20
|
-
# ]
|
|
21
|
-
#
|
|
22
|
-
# For example, the following command-line options (which should not be
|
|
23
|
-
# passed as a string, but as an array of strings):
|
|
24
|
-
#
|
|
25
|
-
# foo -xyz -a hiss -s -m please --level 50 --father=ani -n luke squeak
|
|
26
|
-
#
|
|
27
|
-
# with the following option definitions:
|
|
28
|
-
#
|
|
29
|
-
# [
|
|
30
|
-
# { :short => 'x', :long => 'xxx', :argument => :forbidden },
|
|
31
|
-
# { :short => 'y', :long => 'yyy', :argument => :forbidden },
|
|
32
|
-
# { :short => 'z', :long => 'zzz', :argument => :forbidden },
|
|
33
|
-
# { :short => 'a', :long => 'all', :argument => :forbidden },
|
|
34
|
-
# { :short => 's', :long => 'stuff', :argument => :optional },
|
|
35
|
-
# { :short => 'm', :long => 'more', :argument => :optional },
|
|
36
|
-
# { :short => 'l', :long => 'level', :argument => :required },
|
|
37
|
-
# { :short => 'f', :long => 'father', :argument => :required },
|
|
38
|
-
# { :short => 'n', :long => 'name', :argument => :required }
|
|
39
|
-
# ]
|
|
40
|
-
#
|
|
41
|
-
# will be translated into:
|
|
42
|
-
#
|
|
43
|
-
# {
|
|
44
|
-
# :arguments => [ 'foo', 'hiss', 'squeak' ],
|
|
45
|
-
# :options => {
|
|
46
|
-
# :xxx => true,
|
|
47
|
-
# :yyy => true,
|
|
48
|
-
# :zzz => true,
|
|
49
|
-
# :all => true,
|
|
50
|
-
# :stuff => true,
|
|
51
|
-
# :more => 'please',
|
|
52
|
-
# :level => '50',
|
|
53
|
-
# :father => 'ani',
|
|
54
|
-
# :name => 'luke'
|
|
55
|
-
# }
|
|
56
|
-
# }
|
|
57
|
-
class OptionParser
|
|
4
|
+
# Cri::Parser is used for parsing command-line options and arguments.
|
|
5
|
+
class Parser
|
|
58
6
|
# Error that will be raised when an unknown option is encountered.
|
|
59
7
|
class IllegalOptionError < Cri::Error
|
|
60
8
|
end
|
|
@@ -150,7 +98,7 @@ module Cri
|
|
|
150
98
|
# @raise OptionRequiresAnArgumentError if an option was found that did not
|
|
151
99
|
# have a value, even though this value was required.
|
|
152
100
|
#
|
|
153
|
-
# @return [Cri::
|
|
101
|
+
# @return [Cri::Parser] The option parser self
|
|
154
102
|
def run
|
|
155
103
|
@running = true
|
|
156
104
|
|
data/lib/cri/string_formatter.rb
CHANGED
|
@@ -8,7 +8,7 @@ module Cri
|
|
|
8
8
|
class StringFormatter
|
|
9
9
|
# Extracts individual paragraphs (separated by two newlines).
|
|
10
10
|
#
|
|
11
|
-
# @param [String]
|
|
11
|
+
# @param [String] str The string to format
|
|
12
12
|
#
|
|
13
13
|
# @return [Array<String>] A list of paragraphs in the string
|
|
14
14
|
def to_paragraphs(str)
|
|
@@ -28,7 +28,7 @@ module Cri
|
|
|
28
28
|
|
|
29
29
|
# Word-wraps and indents the string.
|
|
30
30
|
#
|
|
31
|
-
# @param [String]
|
|
31
|
+
# @param [String] str The string to format
|
|
32
32
|
#
|
|
33
33
|
# @param [Number] width The maximal width of each line. This also includes
|
|
34
34
|
# indentation, i.e. the actual maximal width of the text is
|
|
@@ -76,7 +76,7 @@ module Cri
|
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
# @param [String]
|
|
79
|
+
# @param [String] str The string to format
|
|
80
80
|
#
|
|
81
81
|
# @return [String] The string, formatted to be used as a title in a section
|
|
82
82
|
# in the help
|
|
@@ -88,7 +88,7 @@ module Cri
|
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
-
# @param [String]
|
|
91
|
+
# @param [String] str The string to format
|
|
92
92
|
#
|
|
93
93
|
# @return [String] The string, formatted to be used as the name of a command
|
|
94
94
|
# in the help
|
|
@@ -100,7 +100,7 @@ module Cri
|
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
-
# @param [String]
|
|
103
|
+
# @param [String] str The string to format
|
|
104
104
|
#
|
|
105
105
|
# @return [String] The string, formatted to be used as an option definition
|
|
106
106
|
# of a command in the help
|
data/lib/cri/version.rb
CHANGED
data/test/test_argument_list.rb
CHANGED
|
@@ -49,7 +49,7 @@ module Cri
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def test_one_param_defn_matched
|
|
52
|
-
param_defns = [Cri::ParamDefinition.new(name: 'filename')]
|
|
52
|
+
param_defns = [Cri::ParamDefinition.new(name: 'filename', transform: nil)]
|
|
53
53
|
args = Cri::ArgumentList.new(%w[notbad.jpg], false, param_defns)
|
|
54
54
|
|
|
55
55
|
assert_equal(['notbad.jpg'], args.to_a)
|
|
@@ -59,7 +59,7 @@ module Cri
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def test_one_param_defn_too_many
|
|
62
|
-
param_defns = [Cri::ParamDefinition.new(name: 'filename')]
|
|
62
|
+
param_defns = [Cri::ParamDefinition.new(name: 'filename', transform: nil)]
|
|
63
63
|
|
|
64
64
|
exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
|
|
65
65
|
Cri::ArgumentList.new(%w[notbad.jpg verybad.jpg], false, param_defns)
|
|
@@ -68,7 +68,7 @@ module Cri
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def test_one_param_defn_too_few
|
|
71
|
-
param_defns = [Cri::ParamDefinition.new(name: 'filename')]
|
|
71
|
+
param_defns = [Cri::ParamDefinition.new(name: 'filename', transform: nil)]
|
|
72
72
|
|
|
73
73
|
exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
|
|
74
74
|
Cri::ArgumentList.new(%w[], false, param_defns)
|
|
@@ -90,5 +90,15 @@ module Cri
|
|
|
90
90
|
end
|
|
91
91
|
assert_equal('incorrect number of arguments given: expected 0, but got 1', exception.message)
|
|
92
92
|
end
|
|
93
|
+
|
|
94
|
+
def test_transform
|
|
95
|
+
param_defns = [Cri::ParamDefinition.new(name: 'filename', transform: ->(a) { a.upcase })]
|
|
96
|
+
args = Cri::ArgumentList.new(%w[notbad.jpg], false, param_defns)
|
|
97
|
+
|
|
98
|
+
assert_equal(['NOTBAD.JPG'], args.to_a)
|
|
99
|
+
assert_equal(1, args.size)
|
|
100
|
+
assert_equal('NOTBAD.JPG', args[0])
|
|
101
|
+
assert_equal('NOTBAD.JPG', args[:filename])
|
|
102
|
+
end
|
|
93
103
|
end
|
|
94
104
|
end
|
data/test/test_command_dsl.rb
CHANGED
|
@@ -269,6 +269,32 @@ module Cri
|
|
|
269
269
|
assert_equal({ foo: 'a', bar: 'b', qux: 'c' }, $args_sym)
|
|
270
270
|
end
|
|
271
271
|
|
|
272
|
+
def test_params_transform
|
|
273
|
+
# Define
|
|
274
|
+
dsl = Cri::CommandDSL.new
|
|
275
|
+
dsl.instance_eval do
|
|
276
|
+
name 'moo'
|
|
277
|
+
usage 'dunno whatever'
|
|
278
|
+
summary 'does stuff'
|
|
279
|
+
description 'This command does a lot of stuff.'
|
|
280
|
+
|
|
281
|
+
param :foo, transform: ->(a) { a.upcase }
|
|
282
|
+
|
|
283
|
+
run do |_opts, args|
|
|
284
|
+
$args_num = { foo: args[0] }
|
|
285
|
+
$args_sym = { foo: args[:foo] }
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
command = dsl.command
|
|
289
|
+
|
|
290
|
+
# Run
|
|
291
|
+
$args_num = '???'
|
|
292
|
+
$args_sym = '???'
|
|
293
|
+
command.run(%w[abc])
|
|
294
|
+
assert_equal({ foo: 'ABC' }, $args_num)
|
|
295
|
+
assert_equal({ foo: 'ABC' }, $args_sym)
|
|
296
|
+
end
|
|
297
|
+
|
|
272
298
|
def test_no_params_with_one_param_specified
|
|
273
299
|
dsl = Cri::CommandDSL.new
|
|
274
300
|
err = assert_raises Cri::CommandDSL::AlreadySpecifiedWithParams do
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
require 'helper'
|
|
4
4
|
|
|
5
5
|
module Cri
|
|
6
|
-
class
|
|
6
|
+
class ParserTestCase < Cri::TestCase
|
|
7
7
|
def test_parse_without_options
|
|
8
8
|
input = %w[foo bar baz]
|
|
9
9
|
opt_defns = []
|
|
10
10
|
|
|
11
|
-
parser = Cri::
|
|
11
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
12
12
|
|
|
13
13
|
assert_equal({}, parser.options)
|
|
14
14
|
assert_equal(%w[foo bar baz], parser.arguments.to_a)
|
|
@@ -18,8 +18,8 @@ module Cri
|
|
|
18
18
|
input = %w[foo -x]
|
|
19
19
|
opt_defns = []
|
|
20
20
|
|
|
21
|
-
assert_raises(Cri::
|
|
22
|
-
Cri::
|
|
21
|
+
assert_raises(Cri::Parser::IllegalOptionError) do
|
|
22
|
+
Cri::Parser.new(input, opt_defns, [], false).run
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -29,7 +29,7 @@ module Cri
|
|
|
29
29
|
{ long: 'aaa', short: 'a', argument: :forbidden },
|
|
30
30
|
].map { |hash| make_opt_defn(hash) }
|
|
31
31
|
|
|
32
|
-
parser = Cri::
|
|
32
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
33
33
|
|
|
34
34
|
assert(!parser.options[:aaa])
|
|
35
35
|
end
|
|
@@ -40,7 +40,7 @@ module Cri
|
|
|
40
40
|
{ long: 'aaa', short: 'a', argument: :forbidden },
|
|
41
41
|
].map { |hash| make_opt_defn(hash) }
|
|
42
42
|
|
|
43
|
-
parser = Cri::
|
|
43
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
44
44
|
|
|
45
45
|
assert(parser.options[:aaa])
|
|
46
46
|
assert_equal(%w[foo bar], parser.arguments.to_a)
|
|
@@ -52,7 +52,7 @@ module Cri
|
|
|
52
52
|
{ long: 'aaa', short: 'a', argument: :required },
|
|
53
53
|
].map { |hash| make_opt_defn(hash) }
|
|
54
54
|
|
|
55
|
-
parser = Cri::
|
|
55
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
56
56
|
|
|
57
57
|
assert_equal({ aaa: 'xxx' }, parser.options)
|
|
58
58
|
assert_equal(%w[foo bar], parser.arguments.to_a)
|
|
@@ -64,7 +64,7 @@ module Cri
|
|
|
64
64
|
{ long: 'aaa', short: 'a', argument: :required },
|
|
65
65
|
].map { |hash| make_opt_defn(hash) }
|
|
66
66
|
|
|
67
|
-
parser = Cri::
|
|
67
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
68
68
|
|
|
69
69
|
assert_equal({ aaa: 'xxx' }, parser.options)
|
|
70
70
|
assert_equal(%w[foo bar], parser.arguments.to_a)
|
|
@@ -76,8 +76,8 @@ module Cri
|
|
|
76
76
|
{ long: 'aaa', short: 'a', argument: :required },
|
|
77
77
|
].map { |hash| make_opt_defn(hash) }
|
|
78
78
|
|
|
79
|
-
assert_raises(Cri::
|
|
80
|
-
Cri::
|
|
79
|
+
assert_raises(Cri::Parser::OptionRequiresAnArgumentError) do
|
|
80
|
+
Cri::Parser.new(input, opt_defns, [], false).run
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
|
|
@@ -88,8 +88,8 @@ module Cri
|
|
|
88
88
|
{ long: 'port', short: 'p', argument: :required },
|
|
89
89
|
].map { |hash| make_opt_defn(hash) }
|
|
90
90
|
|
|
91
|
-
assert_raises(Cri::
|
|
92
|
-
Cri::
|
|
91
|
+
assert_raises(Cri::Parser::OptionRequiresAnArgumentError) do
|
|
92
|
+
Cri::Parser.new(input, opt_defns, [], false).run
|
|
93
93
|
end
|
|
94
94
|
end
|
|
95
95
|
|
|
@@ -99,7 +99,7 @@ module Cri
|
|
|
99
99
|
{ long: 'aaa', short: 'a', argument: :optional },
|
|
100
100
|
].map { |hash| make_opt_defn(hash) }
|
|
101
101
|
|
|
102
|
-
parser = Cri::
|
|
102
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
103
103
|
|
|
104
104
|
assert(parser.options[:aaa])
|
|
105
105
|
assert_equal(['foo'], parser.arguments.to_a)
|
|
@@ -111,7 +111,7 @@ module Cri
|
|
|
111
111
|
{ long: 'aaa', short: 'a', argument: :optional },
|
|
112
112
|
].map { |hash| make_opt_defn(hash) }
|
|
113
113
|
|
|
114
|
-
parser = Cri::
|
|
114
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
115
115
|
|
|
116
116
|
assert_equal({ aaa: 'xxx' }, parser.options)
|
|
117
117
|
assert_equal(['foo'], parser.arguments.to_a)
|
|
@@ -125,7 +125,7 @@ module Cri
|
|
|
125
125
|
{ long: 'ccc', short: 'c', argument: :forbidden },
|
|
126
126
|
].map { |hash| make_opt_defn(hash) }
|
|
127
127
|
|
|
128
|
-
parser = Cri::
|
|
128
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
129
129
|
|
|
130
130
|
assert(parser.options[:aaa])
|
|
131
131
|
assert(parser.options[:bbb])
|
|
@@ -139,7 +139,7 @@ module Cri
|
|
|
139
139
|
{ long: 'aaa', short: 'a', argument: :forbidden },
|
|
140
140
|
].map { |hash| make_opt_defn(hash) }
|
|
141
141
|
|
|
142
|
-
parser = Cri::
|
|
142
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
143
143
|
|
|
144
144
|
assert(parser.options[:aaa])
|
|
145
145
|
assert_equal(%w[foo bar], parser.arguments.to_a)
|
|
@@ -151,8 +151,8 @@ module Cri
|
|
|
151
151
|
{ long: 'aaa', short: 'a', argument: :required },
|
|
152
152
|
].map { |hash| make_opt_defn(hash) }
|
|
153
153
|
|
|
154
|
-
assert_raises(Cri::
|
|
155
|
-
Cri::
|
|
154
|
+
assert_raises(Cri::Parser::OptionRequiresAnArgumentError) do
|
|
155
|
+
Cri::Parser.new(input, opt_defns, [], false).run
|
|
156
156
|
end
|
|
157
157
|
end
|
|
158
158
|
|
|
@@ -164,7 +164,7 @@ module Cri
|
|
|
164
164
|
{ long: 'ccc', short: 'c', argument: :forbidden },
|
|
165
165
|
].map { |hash| make_opt_defn(hash) }
|
|
166
166
|
|
|
167
|
-
parser = Cri::
|
|
167
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
168
168
|
|
|
169
169
|
assert(parser.options[:aaa])
|
|
170
170
|
assert(parser.options[:bbb])
|
|
@@ -180,7 +180,7 @@ module Cri
|
|
|
180
180
|
{ long: 'ccc', short: 'c', argument: :forbidden },
|
|
181
181
|
].map { |hash| make_opt_defn(hash) }
|
|
182
182
|
|
|
183
|
-
parser = Cri::
|
|
183
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
184
184
|
|
|
185
185
|
assert_equal('bar', parser.options[:aaa])
|
|
186
186
|
assert(parser.options[:bbb])
|
|
@@ -195,8 +195,8 @@ module Cri
|
|
|
195
195
|
{ long: 'port', short: 'p', argument: :required },
|
|
196
196
|
].map { |hash| make_opt_defn(hash) }
|
|
197
197
|
|
|
198
|
-
assert_raises(Cri::
|
|
199
|
-
Cri::
|
|
198
|
+
assert_raises(Cri::Parser::OptionRequiresAnArgumentError) do
|
|
199
|
+
Cri::Parser.new(input, opt_defns, [], false).run
|
|
200
200
|
end
|
|
201
201
|
end
|
|
202
202
|
|
|
@@ -206,7 +206,7 @@ module Cri
|
|
|
206
206
|
{ long: 'aaa', short: 'a', argument: :optional },
|
|
207
207
|
].map { |hash| make_opt_defn(hash) }
|
|
208
208
|
|
|
209
|
-
parser = Cri::
|
|
209
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
210
210
|
|
|
211
211
|
assert(parser.options[:aaa])
|
|
212
212
|
assert_equal(['foo'], parser.arguments.to_a)
|
|
@@ -218,7 +218,7 @@ module Cri
|
|
|
218
218
|
{ long: 'aaa', short: 'a', argument: :optional },
|
|
219
219
|
].map { |hash| make_opt_defn(hash) }
|
|
220
220
|
|
|
221
|
-
parser = Cri::
|
|
221
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
222
222
|
|
|
223
223
|
assert_equal({ aaa: 'xxx' }, parser.options)
|
|
224
224
|
assert_equal(['foo'], parser.arguments.to_a)
|
|
@@ -232,7 +232,7 @@ module Cri
|
|
|
232
232
|
{ long: 'ccc', short: 'c', argument: :forbidden },
|
|
233
233
|
].map { |hash| make_opt_defn(hash) }
|
|
234
234
|
|
|
235
|
-
parser = Cri::
|
|
235
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
236
236
|
|
|
237
237
|
assert(parser.options[:aaa])
|
|
238
238
|
assert(parser.options[:bbb])
|
|
@@ -244,7 +244,7 @@ module Cri
|
|
|
244
244
|
input = %w[foo - bar]
|
|
245
245
|
opt_defns = []
|
|
246
246
|
|
|
247
|
-
parser = Cri::
|
|
247
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
248
248
|
|
|
249
249
|
assert_equal({}, parser.options)
|
|
250
250
|
assert_equal(['foo', '-', 'bar'], parser.arguments.to_a)
|
|
@@ -254,7 +254,7 @@ module Cri
|
|
|
254
254
|
input = %w[foo bar -- -x --yyy -abc]
|
|
255
255
|
opt_defns = []
|
|
256
256
|
|
|
257
|
-
parser = Cri::
|
|
257
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
258
258
|
|
|
259
259
|
assert_equal({}, parser.options)
|
|
260
260
|
assert_equal(['foo', 'bar', '-x', '--yyy', '-abc'], parser.arguments.to_a)
|
|
@@ -266,8 +266,8 @@ module Cri
|
|
|
266
266
|
{ long: 'aaa', short: 'a', argument: :required },
|
|
267
267
|
].map { |hash| make_opt_defn(hash) }
|
|
268
268
|
|
|
269
|
-
assert_raises(Cri::
|
|
270
|
-
Cri::
|
|
269
|
+
assert_raises(Cri::Parser::OptionRequiresAnArgumentError) do
|
|
270
|
+
Cri::Parser.new(input, opt_defns, [], false).run
|
|
271
271
|
end
|
|
272
272
|
end
|
|
273
273
|
|
|
@@ -278,7 +278,7 @@ module Cri
|
|
|
278
278
|
{ long: 'verbose', short: 'v', multiple: true },
|
|
279
279
|
].map { |hash| make_opt_defn(hash) }
|
|
280
280
|
|
|
281
|
-
parser = Cri::
|
|
281
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
282
282
|
|
|
283
283
|
assert_equal(%w[test test2], parser.options[:long])
|
|
284
284
|
assert_equal(3, parser.options[:verbose].size)
|
|
@@ -290,7 +290,7 @@ module Cri
|
|
|
290
290
|
{ long: 'animal', short: 'a', argument: :required, default: 'donkey' },
|
|
291
291
|
].map { |hash| make_opt_defn(hash) }
|
|
292
292
|
|
|
293
|
-
parser = Cri::
|
|
293
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
294
294
|
|
|
295
295
|
assert_equal({ animal: 'donkey' }, parser.options)
|
|
296
296
|
assert_equal(['foo'], parser.arguments.to_a)
|
|
@@ -302,8 +302,8 @@ module Cri
|
|
|
302
302
|
{ long: 'animal', short: 'a', argument: :required, default: 'donkey' },
|
|
303
303
|
].map { |hash| make_opt_defn(hash) }
|
|
304
304
|
|
|
305
|
-
assert_raises(Cri::
|
|
306
|
-
Cri::
|
|
305
|
+
assert_raises(Cri::Parser::OptionRequiresAnArgumentError) do
|
|
306
|
+
Cri::Parser.new(input, opt_defns, [], false).run
|
|
307
307
|
end
|
|
308
308
|
end
|
|
309
309
|
|
|
@@ -313,7 +313,7 @@ module Cri
|
|
|
313
313
|
{ long: 'animal', short: 'a', argument: :required, default: 'donkey' },
|
|
314
314
|
].map { |hash| make_opt_defn(hash) }
|
|
315
315
|
|
|
316
|
-
parser = Cri::
|
|
316
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
317
317
|
|
|
318
318
|
assert_equal({ animal: 'giraffe' }, parser.options)
|
|
319
319
|
assert_equal(['foo'], parser.arguments.to_a)
|
|
@@ -325,7 +325,7 @@ module Cri
|
|
|
325
325
|
{ long: 'animal', short: 'a', argument: :optional, default: 'donkey' },
|
|
326
326
|
].map { |hash| make_opt_defn(hash) }
|
|
327
327
|
|
|
328
|
-
parser = Cri::
|
|
328
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
329
329
|
|
|
330
330
|
assert_equal({ animal: 'donkey' }, parser.options)
|
|
331
331
|
assert_equal(['foo'], parser.arguments.to_a)
|
|
@@ -337,7 +337,7 @@ module Cri
|
|
|
337
337
|
{ long: 'animal', short: 'a', argument: :optional, default: 'donkey' },
|
|
338
338
|
].map { |hash| make_opt_defn(hash) }
|
|
339
339
|
|
|
340
|
-
parser = Cri::
|
|
340
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
341
341
|
|
|
342
342
|
assert_equal({ animal: 'donkey' }, parser.options)
|
|
343
343
|
assert_equal(['foo'], parser.arguments.to_a)
|
|
@@ -349,7 +349,7 @@ module Cri
|
|
|
349
349
|
{ long: 'animal', short: 'a', argument: :optional, default: 'donkey' },
|
|
350
350
|
].map { |hash| make_opt_defn(hash) }
|
|
351
351
|
|
|
352
|
-
parser = Cri::
|
|
352
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
353
353
|
|
|
354
354
|
assert_equal({ animal: 'giraffe' }, parser.options)
|
|
355
355
|
assert_equal(['foo'], parser.arguments.to_a)
|
|
@@ -361,7 +361,7 @@ module Cri
|
|
|
361
361
|
{ long: 'animal', short: 'a', argument: :optional, default: 'donkey' },
|
|
362
362
|
].map { |hash| make_opt_defn(hash) }
|
|
363
363
|
|
|
364
|
-
parser = Cri::
|
|
364
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
365
365
|
|
|
366
366
|
assert_equal({ animal: 'gi' }, parser.options)
|
|
367
367
|
assert_equal(%w[foo raffe], parser.arguments.to_a)
|
|
@@ -375,7 +375,7 @@ module Cri
|
|
|
375
375
|
{ long: 'ccc', short: 'c', argument: :required },
|
|
376
376
|
].map { |hash| make_opt_defn(hash) }
|
|
377
377
|
|
|
378
|
-
parser = Cri::
|
|
378
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
379
379
|
|
|
380
380
|
assert_equal({ aaa: true, bbb: 'xxx', ccc: 'yyy' }, parser.options)
|
|
381
381
|
assert_equal(%w[foo zzz], parser.arguments.to_a)
|
|
@@ -389,7 +389,7 @@ module Cri
|
|
|
389
389
|
{ long: 'ccc', short: 'c', argument: :required },
|
|
390
390
|
].map { |hash| make_opt_defn(hash) }
|
|
391
391
|
|
|
392
|
-
parser = Cri::
|
|
392
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
393
393
|
|
|
394
394
|
assert_equal({ aaa: true, bbb: 'xxx', ccc: 'yyy' }, parser.options)
|
|
395
395
|
assert_equal(%w[foo zzz], parser.arguments.to_a)
|
|
@@ -403,7 +403,7 @@ module Cri
|
|
|
403
403
|
{ long: 'ccc', short: 'c', argument: :optional, default: 'c default' },
|
|
404
404
|
].map { |hash| make_opt_defn(hash) }
|
|
405
405
|
|
|
406
|
-
parser = Cri::
|
|
406
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
407
407
|
|
|
408
408
|
assert_equal({ aaa: true, bbb: 'xxx', ccc: 'c default' }, parser.options)
|
|
409
409
|
assert_equal(%w[foo], parser.arguments.to_a)
|
|
@@ -415,7 +415,7 @@ module Cri
|
|
|
415
415
|
{ long: 'port', short: 'p', argument: :required, transform: ->(x) { Integer(x) } },
|
|
416
416
|
].map { |hash| make_opt_defn(hash) }
|
|
417
417
|
|
|
418
|
-
parser = Cri::
|
|
418
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
419
419
|
|
|
420
420
|
assert_equal({ port: 123 }, parser.options)
|
|
421
421
|
assert_equal([], parser.arguments.to_a)
|
|
@@ -427,7 +427,7 @@ module Cri
|
|
|
427
427
|
{ long: 'port', short: 'p', argument: :required, transform: method(:Integer) },
|
|
428
428
|
].map { |hash| make_opt_defn(hash) }
|
|
429
429
|
|
|
430
|
-
parser = Cri::
|
|
430
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
431
431
|
|
|
432
432
|
assert_equal({ port: 123 }, parser.options)
|
|
433
433
|
assert_equal([], parser.arguments.to_a)
|
|
@@ -445,7 +445,7 @@ module Cri
|
|
|
445
445
|
{ long: 'port', short: 'p', argument: :required, transform: port },
|
|
446
446
|
].map { |hash| make_opt_defn(hash) }
|
|
447
447
|
|
|
448
|
-
parser = Cri::
|
|
448
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
449
449
|
|
|
450
450
|
assert_equal({ port: 123 }, parser.options)
|
|
451
451
|
assert_equal([], parser.arguments.to_a)
|
|
@@ -464,7 +464,7 @@ module Cri
|
|
|
464
464
|
{ long: 'port', short: 'p', argument: :required, default: 8080, transform: port },
|
|
465
465
|
].map { |hash| make_opt_defn(hash) }
|
|
466
466
|
|
|
467
|
-
parser = Cri::
|
|
467
|
+
parser = Cri::Parser.new(input, opt_defns, [], false).run
|
|
468
468
|
|
|
469
469
|
assert_equal({ port: 8080 }, parser.options)
|
|
470
470
|
assert_equal([], parser.arguments.to_a)
|
|
@@ -476,8 +476,8 @@ module Cri
|
|
|
476
476
|
{ long: 'port', short: 'p', argument: :required, transform: method(:Integer) },
|
|
477
477
|
].map { |hash| make_opt_defn(hash) }
|
|
478
478
|
|
|
479
|
-
exception = assert_raises(Cri::
|
|
480
|
-
Cri::
|
|
479
|
+
exception = assert_raises(Cri::Parser::IllegalOptionValueError) do
|
|
480
|
+
Cri::Parser.new(input, opt_defns, [], false).run
|
|
481
481
|
end
|
|
482
482
|
assert_equal('invalid value "one_hundred_and_twenty_three" for --port option', exception.message)
|
|
483
483
|
end
|
|
@@ -485,10 +485,10 @@ module Cri
|
|
|
485
485
|
def test_parse_with_param_defns
|
|
486
486
|
input = %w[localhost]
|
|
487
487
|
param_defns = [
|
|
488
|
-
{ name: 'host' },
|
|
488
|
+
{ name: 'host', transform: nil },
|
|
489
489
|
].map { |hash| Cri::ParamDefinition.new(hash) }
|
|
490
490
|
|
|
491
|
-
parser = Cri::
|
|
491
|
+
parser = Cri::Parser.new(input, [], param_defns, false).run
|
|
492
492
|
assert_equal({}, parser.options)
|
|
493
493
|
assert_equal('localhost', parser.arguments[0])
|
|
494
494
|
assert_equal('localhost', parser.arguments[:host])
|
|
@@ -497,10 +497,10 @@ module Cri
|
|
|
497
497
|
def test_parse_with_param_defns_too_few_args
|
|
498
498
|
input = []
|
|
499
499
|
param_defns = [
|
|
500
|
-
{ name: 'host' },
|
|
500
|
+
{ name: 'host', transform: nil },
|
|
501
501
|
].map { |hash| Cri::ParamDefinition.new(hash) }
|
|
502
502
|
|
|
503
|
-
parser = Cri::
|
|
503
|
+
parser = Cri::Parser.new(input, [], param_defns, false).run
|
|
504
504
|
exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
|
|
505
505
|
parser.arguments
|
|
506
506
|
end
|
|
@@ -510,10 +510,10 @@ module Cri
|
|
|
510
510
|
def test_parse_with_param_defns_too_many_args
|
|
511
511
|
input = %w[localhost oink]
|
|
512
512
|
param_defns = [
|
|
513
|
-
{ name: 'host' },
|
|
513
|
+
{ name: 'host', transform: nil },
|
|
514
514
|
].map { |hash| Cri::ParamDefinition.new(hash) }
|
|
515
515
|
|
|
516
|
-
parser = Cri::
|
|
516
|
+
parser = Cri::Parser.new(input, [], param_defns, false).run
|
|
517
517
|
exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
|
|
518
518
|
parser.arguments
|
|
519
519
|
end
|
|
@@ -523,10 +523,10 @@ module Cri
|
|
|
523
523
|
def test_parse_with_param_defns_invalid_key
|
|
524
524
|
input = %w[localhost]
|
|
525
525
|
param_defns = [
|
|
526
|
-
{ name: 'host' },
|
|
526
|
+
{ name: 'host', transform: nil },
|
|
527
527
|
].map { |hash| Cri::ParamDefinition.new(hash) }
|
|
528
528
|
|
|
529
|
-
parser = Cri::
|
|
529
|
+
parser = Cri::Parser.new(input, [], param_defns, false).run
|
|
530
530
|
|
|
531
531
|
exception = assert_raises(ArgumentError) do
|
|
532
532
|
parser.arguments['oink']
|
|
@@ -537,11 +537,11 @@ module Cri
|
|
|
537
537
|
def test_parse_with_param_defns_two_params
|
|
538
538
|
input = %w[localhost example.com]
|
|
539
539
|
param_defns = [
|
|
540
|
-
{ name: 'source' },
|
|
541
|
-
{ name: 'target' },
|
|
540
|
+
{ name: 'source', transform: nil },
|
|
541
|
+
{ name: 'target', transform: nil },
|
|
542
542
|
].map { |hash| Cri::ParamDefinition.new(hash) }
|
|
543
543
|
|
|
544
|
-
parser = Cri::
|
|
544
|
+
parser = Cri::Parser.new(input, [], param_defns, false).run
|
|
545
545
|
assert_equal({}, parser.options)
|
|
546
546
|
assert_equal('localhost', parser.arguments[0])
|
|
547
547
|
assert_equal('localhost', parser.arguments[:source])
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cri
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.15.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Denis Defreyne
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-08-
|
|
11
|
+
date: 2018-08-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colored
|
|
@@ -65,8 +65,8 @@ files:
|
|
|
65
65
|
- lib/cri/commands/basic_root.rb
|
|
66
66
|
- lib/cri/help_renderer.rb
|
|
67
67
|
- lib/cri/option_definition.rb
|
|
68
|
-
- lib/cri/option_parser.rb
|
|
69
68
|
- lib/cri/param_definition.rb
|
|
69
|
+
- lib/cri/parser.rb
|
|
70
70
|
- lib/cri/platform.rb
|
|
71
71
|
- lib/cri/string_formatter.rb
|
|
72
72
|
- lib/cri/version.rb
|
|
@@ -79,7 +79,7 @@ files:
|
|
|
79
79
|
- test/test_command_dsl.rb
|
|
80
80
|
- test/test_command_runner.rb
|
|
81
81
|
- test/test_help_renderer.rb
|
|
82
|
-
- test/
|
|
82
|
+
- test/test_parser.rb
|
|
83
83
|
- test/test_string_formatter.rb
|
|
84
84
|
homepage: http://stoneship.org/software/cri/
|
|
85
85
|
licenses:
|