cri 2.15.10 → 2.15.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +32 -21
- data/NEWS.md +10 -0
- data/README.md +69 -69
- data/cri.gemspec +1 -1
- data/lib/cri/argument_list.rb +1 -6
- data/lib/cri/command.rb +2 -0
- data/lib/cri/command_dsl.rb +2 -11
- data/lib/cri/parser.rb +3 -5
- data/lib/cri/version.rb +1 -1
- data/test/test_parser.rb +5 -5
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 823a030106960498adbfd77e19f3ef8b30fdfc6b2b592604ced4c875c8ced9f4
|
4
|
+
data.tar.gz: 8663621247fffc1be92d538c7cc5d594522e2a350a126236abfe761a15973a5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a3c3038f8629238aa071a1d7dd94aee5e7f3e85df7fe097a67176c0300c2a69a3dc576da76354056e8d366ca5b6bae0806b5f0cea3f2854c6c88cafb0150bb3
|
7
|
+
data.tar.gz: 7d810e46680ee4802db459510635d2c9857aa400794e09d5d43a903e6ffc0edee0221ce17906f216f543892b9f5ac2f0eb71fa447b1771a9e8f12ac159d5bda8
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,39 +1,48 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cri (2.15.
|
4
|
+
cri (2.15.11)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
ast (2.4.
|
9
|
+
ast (2.4.1)
|
10
10
|
coveralls (0.8.23)
|
11
11
|
json (>= 1.8, < 3)
|
12
12
|
simplecov (~> 0.16.1)
|
13
13
|
term-ansicolor (~> 1.3)
|
14
14
|
thor (>= 0.19.4, < 2.0)
|
15
15
|
tins (~> 1.6)
|
16
|
-
docile (1.3.
|
17
|
-
|
18
|
-
json (2.3.0)
|
16
|
+
docile (1.3.4)
|
17
|
+
json (2.5.1)
|
19
18
|
m (1.5.1)
|
20
19
|
method_source (>= 0.6.7)
|
21
20
|
rake (>= 0.9.2.2)
|
22
|
-
method_source (0.
|
23
|
-
minitest (5.14.
|
24
|
-
parallel (1.
|
25
|
-
parser (
|
26
|
-
ast (~> 2.4.
|
21
|
+
method_source (1.0.0)
|
22
|
+
minitest (5.14.2)
|
23
|
+
parallel (1.20.1)
|
24
|
+
parser (3.0.0.0)
|
25
|
+
ast (~> 2.4.1)
|
27
26
|
rainbow (3.0.0)
|
28
|
-
rake (13.0.
|
29
|
-
|
30
|
-
|
27
|
+
rake (13.0.3)
|
28
|
+
regexp_parser (2.0.3)
|
29
|
+
rexml (3.2.4)
|
30
|
+
rubocop (1.7.0)
|
31
31
|
parallel (~> 1.10)
|
32
|
-
parser (>= 2.7.
|
32
|
+
parser (>= 2.7.1.5)
|
33
33
|
rainbow (>= 2.2.2, < 4.0)
|
34
|
+
regexp_parser (>= 1.8, < 3.0)
|
35
|
+
rexml
|
36
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
34
37
|
ruby-progressbar (~> 1.7)
|
35
|
-
unicode-display_width (>= 1.4.0, <
|
36
|
-
|
38
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
39
|
+
rubocop-ast (1.3.0)
|
40
|
+
parser (>= 2.7.1.5)
|
41
|
+
rubocop-minitest (0.10.2)
|
42
|
+
rubocop (>= 0.87, < 2.0)
|
43
|
+
rubocop-rake (0.5.1)
|
44
|
+
rubocop
|
45
|
+
ruby-progressbar (1.11.0)
|
37
46
|
simplecov (0.16.1)
|
38
47
|
docile (~> 1.1)
|
39
48
|
json (>= 1.8, < 3)
|
@@ -43,13 +52,13 @@ GEM
|
|
43
52
|
term-ansicolor (1.7.1)
|
44
53
|
tins (~> 1.0)
|
45
54
|
thor (1.0.1)
|
46
|
-
tins (1.
|
55
|
+
tins (1.26.0)
|
47
56
|
sync
|
48
|
-
unicode-display_width (1.
|
49
|
-
yard (0.9.
|
57
|
+
unicode-display_width (1.7.0)
|
58
|
+
yard (0.9.26)
|
50
59
|
|
51
60
|
PLATFORMS
|
52
|
-
|
61
|
+
x86_64-darwin-20
|
53
62
|
|
54
63
|
DEPENDENCIES
|
55
64
|
coveralls
|
@@ -58,7 +67,9 @@ DEPENDENCIES
|
|
58
67
|
minitest
|
59
68
|
rake
|
60
69
|
rubocop
|
70
|
+
rubocop-minitest (~> 0.10.2)
|
71
|
+
rubocop-rake (~> 0.5.1)
|
61
72
|
yard
|
62
73
|
|
63
74
|
BUNDLED WITH
|
64
|
-
2.
|
75
|
+
2.2.3
|
data/NEWS.md
CHANGED
data/README.md
CHANGED
@@ -12,14 +12,14 @@ nested commands.
|
|
12
12
|
|
13
13
|
## Requirements
|
14
14
|
|
15
|
-
Cri requires Ruby 2.
|
15
|
+
Cri requires Ruby 2.5 or newer (including Ruby 3.x).
|
16
16
|
|
17
17
|
## Compatibility policy
|
18
18
|
|
19
19
|
Cri is guaranteed to be supported on any [officially supported Ruby version](https://www.ruby-lang.org/en/downloads/branches/), as well as the version of Ruby that comes by default on
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
- the last two [Ubuntu LTS releases](https://wiki.ubuntu.com/Releases)
|
22
|
+
- the last two major [macOS releases](https://en.wikipedia.org/wiki/MacOS_version_history)
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
@@ -119,101 +119,101 @@ The most generic way of definition an option is using either `#option` or `#opt`
|
|
119
119
|
2. a long option name
|
120
120
|
3. a description
|
121
121
|
4. optional extra parameters
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
122
|
+
- `argument:` (default: `:forbidden`)
|
123
|
+
- `transform:`
|
124
|
+
- `default:`
|
125
|
+
- `multiple:` (default: `false`)
|
126
126
|
5. optionally, a block
|
127
127
|
|
128
128
|
In more detail:
|
129
129
|
|
130
|
-
|
130
|
+
- The short option name is a symbol containing one character, to be used in single-dash options, e.g. `:f` (corresponds to `-f`). The long option name is a symbol containing a string, to be used in double-dash options, e.g. `:force` (corresponds to `--force`). Either the short or the long option name can be nil, but not both.
|
131
131
|
|
132
|
-
|
132
|
+
- The description is a short, one-line text that shows up in the command’s help. For example, the `-v`/`--version` option might have the description `show version information and quit`.
|
133
133
|
|
134
|
-
|
134
|
+
- The extra parameters, `argument:`, `multiple:`, `default:`, and `transform:`, are described in the sections below.
|
135
135
|
|
136
|
-
|
136
|
+
- The block, if given, will be executed when the option is found. The arguments to the block are the option value (`true` in case the option does not have an argument) and the command.
|
137
137
|
|
138
138
|
There are several convenience methods that are alternatives to `#option`/`#opt`:
|
139
139
|
|
140
|
-
|
141
|
-
|
142
|
-
|
140
|
+
- `#flag` sets `argument:` to `:forbidden`
|
141
|
+
- (**deprecated**) `#required` sets `argument:` to `:required` -- deprecated because `#required` suggests that the option is required, wich is incorrect; the _argument_ is required.)
|
142
|
+
- (**deprecated**) `#optional` sets `argument:` to `:optional` -- deprecated because `#optional` looks too similar to `#option`.
|
143
143
|
|
144
144
|
#### Forbidden, required, and optional arguments (`argument:`)
|
145
145
|
|
146
146
|
The `:argument` parameter can be set to `:forbidden`, `:required`, or `:optional`.
|
147
147
|
|
148
|
-
|
148
|
+
- `:forbidden` means that when the option is present, the value will be set to `true`, and `false` otherwise. For example:
|
149
149
|
|
150
|
-
|
151
|
-
|
150
|
+
```ruby
|
151
|
+
option :f, :force, 'push with force', argument: :forbidden
|
152
152
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
153
|
+
run do |opts, args, cmd|
|
154
|
+
puts "Force? #{opts[:force]}"
|
155
|
+
end
|
156
|
+
```
|
157
157
|
|
158
|
-
|
159
|
-
|
160
|
-
|
158
|
+
```sh
|
159
|
+
% ./push mypackage.zip
|
160
|
+
Force? false
|
161
161
|
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
% ./push --force mypackage.zip
|
163
|
+
Force? true
|
164
|
+
```
|
165
165
|
|
166
|
-
|
166
|
+
`:argument` is set to `:forbidden` by default.
|
167
167
|
|
168
|
-
|
168
|
+
- `:required` means that the option must be followed by an argument, which will then be treated as the value for the option. It does not mean that the option itself is required. For example:
|
169
169
|
|
170
|
-
|
171
|
-
|
172
|
-
|
170
|
+
```ruby
|
171
|
+
option :o, :output, 'specify output file', argument: :required
|
172
|
+
option :f, :fast, 'fetch faster', argument: :forbidden
|
173
173
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
174
|
+
run do |opts, args, cmd|
|
175
|
+
puts "Output file: #{opts[:output]}"
|
176
|
+
end
|
177
|
+
```
|
178
178
|
|
179
|
-
|
180
|
-
|
181
|
-
|
179
|
+
```sh
|
180
|
+
% ./fetch http://example.com/source.zip
|
181
|
+
Output file: nil
|
182
182
|
|
183
|
-
|
184
|
-
|
183
|
+
% ./fetch --output example.zip http://example.com/source.zip
|
184
|
+
Output file: example.zip
|
185
185
|
|
186
|
-
|
187
|
-
|
186
|
+
% ./fetch http://example.com/source.zip --output
|
187
|
+
fetch: option requires an argument -- output
|
188
188
|
|
189
|
-
|
190
|
-
|
191
|
-
|
189
|
+
% ./fetch --output --fast http://example.com/source.zip
|
190
|
+
fetch: option requires an argument -- output
|
191
|
+
```
|
192
192
|
|
193
|
-
|
193
|
+
- `:optional` means that the option can be followed by an argument. If it is, then the argument is treated as the value for the option; if it isn’t, the value for the option will be `true`. For example:
|
194
194
|
|
195
|
-
|
196
|
-
|
197
|
-
|
195
|
+
```ruby
|
196
|
+
option :o, :output, 'specify output file', argument: :optional
|
197
|
+
option :f, :fast, 'fetch faster', argument: :forbidden
|
198
198
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
199
|
+
run do |opts, args, cmd|
|
200
|
+
puts "Output file: #{opts[:output]}"
|
201
|
+
end
|
202
|
+
```
|
203
203
|
|
204
|
-
|
205
|
-
|
206
|
-
|
204
|
+
```sh
|
205
|
+
% ./fetch http://example.com/source.zip
|
206
|
+
Output file: nil
|
207
207
|
|
208
|
-
|
209
|
-
|
208
|
+
% ./fetch --output example.zip http://example.com/source.zip
|
209
|
+
Output file: example.zip
|
210
210
|
|
211
|
-
|
212
|
-
|
211
|
+
% ./fetch http://example.com/source.zip --output
|
212
|
+
Output file: true
|
213
213
|
|
214
|
-
|
215
|
-
|
216
|
-
|
214
|
+
% ./fetch --output --fast http://example.com/source.zip
|
215
|
+
Output file: true
|
216
|
+
```
|
217
217
|
|
218
218
|
#### Transforming options (`transform:`)
|
219
219
|
|
@@ -374,7 +374,7 @@ As with options, parameter definitions take `transform:`, which can be used for
|
|
374
374
|
param :port, transform: method(:Integer)
|
375
375
|
```
|
376
376
|
|
377
|
-
(
|
377
|
+
(_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`.)
|
378
378
|
|
379
379
|
### Allowing arbitrary arguments
|
380
380
|
|
@@ -584,10 +584,10 @@ cmd = Cri::Command.load_file('commands/check.rb', infer_name: true)
|
|
584
584
|
|
585
585
|
## Contributors
|
586
586
|
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
587
|
+
- Bart Mesuere
|
588
|
+
- Ken Coar
|
589
|
+
- Tim Sharpe
|
590
|
+
- Toon Willems
|
591
591
|
|
592
592
|
Thanks for Lee “injekt” Jarvis for [Slop](https://github.com/injekt/slop),
|
593
593
|
which has inspired the design of Cri 2.0.
|
data/cri.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.files = Dir['[A-Z]*'] + Dir['{lib,test}/**/*'] + ['cri.gemspec']
|
17
17
|
s.require_paths = ['lib']
|
18
18
|
|
19
|
-
s.required_ruby_version = '
|
19
|
+
s.required_ruby_version = '>= 2.5'
|
20
20
|
|
21
21
|
s.rdoc_options = ['--main', 'README.md']
|
22
22
|
s.extra_rdoc_files = ['LICENSE', 'README.md', 'NEWS.md']
|
data/lib/cri/argument_list.rb
CHANGED
@@ -6,12 +6,7 @@ module Cri
|
|
6
6
|
# Error that will be raised when an incorrect number of arguments is given.
|
7
7
|
class ArgumentCountMismatchError < Cri::Error
|
8
8
|
def initialize(expected_count, actual_count)
|
9
|
-
|
10
|
-
@actual_count = actual_count
|
11
|
-
end
|
12
|
-
|
13
|
-
def message
|
14
|
-
"incorrect number of arguments given: expected #{@expected_count}, but got #{@actual_count}"
|
9
|
+
super("incorrect number of arguments given: expected #{expected_count}, but got #{actual_count}")
|
15
10
|
end
|
16
11
|
end
|
17
12
|
|
data/lib/cri/command.rb
CHANGED
data/lib/cri/command_dsl.rb
CHANGED
@@ -8,12 +8,7 @@ module Cri
|
|
8
8
|
# already declared as taken no params.
|
9
9
|
class AlreadySpecifiedAsNoParams < Cri::Error
|
10
10
|
def initialize(param, command)
|
11
|
-
|
12
|
-
@command = command
|
13
|
-
end
|
14
|
-
|
15
|
-
def message
|
16
|
-
"Attempted to specify a parameter #{@param.inspect} to the command #{@command.name.inspect}, which is already specified as taking no params. Suggestion: remove the #no_params call."
|
11
|
+
super("Attempted to specify a parameter #{param.inspect} to the command #{command.name.inspect}, which is already specified as taking no params. Suggestion: remove the #no_params call.")
|
17
12
|
end
|
18
13
|
end
|
19
14
|
|
@@ -21,11 +16,7 @@ module Cri
|
|
21
16
|
# parameters, when the command is already declared with parameters.
|
22
17
|
class AlreadySpecifiedWithParams < Cri::Error
|
23
18
|
def initialize(command)
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def message
|
28
|
-
"Attempted to declare the command #{@command.name.inspect} as taking no parameters, but some parameters are already declared for this command. Suggestion: remove the #no_params call."
|
19
|
+
super("Attempted to declare the command #{command.name.inspect} as taking no parameters, but some parameters are already declared for this command. Suggestion: remove the #no_params call.")
|
29
20
|
end
|
30
21
|
end
|
31
22
|
|
data/lib/cri/parser.rb
CHANGED
@@ -14,12 +14,10 @@ module Cri
|
|
14
14
|
attr_reader :value
|
15
15
|
|
16
16
|
def initialize(definition, value)
|
17
|
-
|
18
|
-
@value = value
|
19
|
-
end
|
17
|
+
super("invalid value #{value.inspect} for #{definition.formatted_name} option")
|
20
18
|
|
21
|
-
|
22
|
-
|
19
|
+
@value = value
|
20
|
+
@definition = definition
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
data/lib/cri/version.rb
CHANGED
data/test/test_parser.rb
CHANGED
@@ -443,7 +443,7 @@ module Cri
|
|
443
443
|
input = %w[localhost]
|
444
444
|
param_defns = [
|
445
445
|
{ name: 'host', transform: nil },
|
446
|
-
].map { |hash| Cri::ParamDefinition.new(hash) }
|
446
|
+
].map { |hash| Cri::ParamDefinition.new(**hash) }
|
447
447
|
|
448
448
|
parser = Cri::Parser.new(input, [], param_defns, false).run
|
449
449
|
assert_equal({}, parser.options)
|
@@ -455,7 +455,7 @@ module Cri
|
|
455
455
|
input = []
|
456
456
|
param_defns = [
|
457
457
|
{ name: 'host', transform: nil },
|
458
|
-
].map { |hash| Cri::ParamDefinition.new(hash) }
|
458
|
+
].map { |hash| Cri::ParamDefinition.new(**hash) }
|
459
459
|
|
460
460
|
parser = Cri::Parser.new(input, [], param_defns, false).run
|
461
461
|
exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
|
@@ -468,7 +468,7 @@ module Cri
|
|
468
468
|
input = %w[localhost oink]
|
469
469
|
param_defns = [
|
470
470
|
{ name: 'host', transform: nil },
|
471
|
-
].map { |hash| Cri::ParamDefinition.new(hash) }
|
471
|
+
].map { |hash| Cri::ParamDefinition.new(**hash) }
|
472
472
|
|
473
473
|
parser = Cri::Parser.new(input, [], param_defns, false).run
|
474
474
|
exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
|
@@ -481,7 +481,7 @@ module Cri
|
|
481
481
|
input = %w[localhost]
|
482
482
|
param_defns = [
|
483
483
|
{ name: 'host', transform: nil },
|
484
|
-
].map { |hash| Cri::ParamDefinition.new(hash) }
|
484
|
+
].map { |hash| Cri::ParamDefinition.new(**hash) }
|
485
485
|
|
486
486
|
parser = Cri::Parser.new(input, [], param_defns, false).run
|
487
487
|
|
@@ -496,7 +496,7 @@ module Cri
|
|
496
496
|
param_defns = [
|
497
497
|
{ name: 'source', transform: nil },
|
498
498
|
{ name: 'target', transform: nil },
|
499
|
-
].map { |hash| Cri::ParamDefinition.new(hash) }
|
499
|
+
].map { |hash| Cri::ParamDefinition.new(**hash) }
|
500
500
|
|
501
501
|
parser = Cri::Parser.new(input, [], param_defns, false).run
|
502
502
|
assert_equal({}, parser.options)
|
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.15.
|
4
|
+
version: 2.15.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Defreyne
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Cri allows building easy-to-use command-line interfaces with support
|
14
14
|
for subcommands.
|
@@ -57,7 +57,7 @@ homepage: https://github.com/ddfreyne/cri
|
|
57
57
|
licenses:
|
58
58
|
- MIT
|
59
59
|
metadata: {}
|
60
|
-
post_install_message:
|
60
|
+
post_install_message:
|
61
61
|
rdoc_options:
|
62
62
|
- "--main"
|
63
63
|
- README.md
|
@@ -65,17 +65,17 @@ require_paths:
|
|
65
65
|
- lib
|
66
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- - "
|
68
|
+
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version: '2.
|
70
|
+
version: '2.5'
|
71
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
78
|
-
signing_key:
|
77
|
+
rubygems_version: 3.2.3
|
78
|
+
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: a library for building easy-to-use command-line tools
|
81
81
|
test_files: []
|