cri 2.9.1 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile.lock +12 -12
- data/NEWS.md +8 -0
- data/README.adoc +27 -0
- data/cri.gemspec +2 -2
- data/lib/cri/command.rb +28 -16
- data/lib/cri/command_dsl.rb +8 -0
- data/lib/cri/version.rb +1 -1
- data/test/test_command.rb +41 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8769d8c9e623dfdb32230dd41b0edf1c3338e6c
|
4
|
+
data.tar.gz: 9c32cc3d1663daaddb84e311886267b08e4cb807
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed77cf3c93c80192d56d0fe74d2fc014b7369e41e5d3d0359af104718446bf785099d649b38b6cdd3949c60177e4d5184b421ae132405639342fad10d51980a8
|
7
|
+
data.tar.gz: 96c05721d3e212bd677248932453f5583f1a1e08a90020fb3d70b8439c6ac8ba0748ef4a191e5db46f9bad00349d765f3ff3ed944285f5a6b88992572b17196b
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at denis+cri-coc@stoneship.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cri (2.
|
4
|
+
cri (2.10.0)
|
5
5
|
colored (~> 1.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
asciidoctor (1.5.
|
10
|
+
asciidoctor (1.5.6.1)
|
11
11
|
ast (2.3.0)
|
12
12
|
colored (1.2)
|
13
13
|
coveralls (0.8.21)
|
@@ -18,32 +18,32 @@ GEM
|
|
18
18
|
tins (~> 1.6)
|
19
19
|
docile (1.1.5)
|
20
20
|
json (2.1.0)
|
21
|
-
minitest (5.10.
|
22
|
-
parallel (1.
|
21
|
+
minitest (5.10.3)
|
22
|
+
parallel (1.12.0)
|
23
23
|
parser (2.4.0.0)
|
24
24
|
ast (~> 2.2)
|
25
25
|
powerpack (0.1.1)
|
26
26
|
rainbow (2.2.2)
|
27
27
|
rake
|
28
|
-
rake (12.
|
29
|
-
rubocop (0.
|
28
|
+
rake (12.2.1)
|
29
|
+
rubocop (0.51.0)
|
30
30
|
parallel (~> 1.10)
|
31
31
|
parser (>= 2.3.3.1, < 3.0)
|
32
32
|
powerpack (~> 0.1)
|
33
|
-
rainbow (>=
|
33
|
+
rainbow (>= 2.2.2, < 3.0)
|
34
34
|
ruby-progressbar (~> 1.7)
|
35
35
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
36
|
-
ruby-progressbar (1.
|
36
|
+
ruby-progressbar (1.9.0)
|
37
37
|
simplecov (0.14.1)
|
38
38
|
docile (~> 1.1.0)
|
39
39
|
json (>= 1.8, < 3)
|
40
40
|
simplecov-html (~> 0.10.0)
|
41
|
-
simplecov-html (0.10.
|
41
|
+
simplecov-html (0.10.2)
|
42
42
|
term-ansicolor (1.6.0)
|
43
43
|
tins (~> 1.0)
|
44
44
|
thor (0.19.4)
|
45
|
-
tins (1.
|
46
|
-
unicode-display_width (1.
|
45
|
+
tins (1.15.0)
|
46
|
+
unicode-display_width (1.3.0)
|
47
47
|
yard (0.9.9)
|
48
48
|
|
49
49
|
PLATFORMS
|
@@ -60,4 +60,4 @@ DEPENDENCIES
|
|
60
60
|
yard
|
61
61
|
|
62
62
|
BUNDLED WITH
|
63
|
-
1.15.
|
63
|
+
1.15.4
|
data/NEWS.md
CHANGED
data/README.adoc
CHANGED
@@ -174,6 +174,33 @@ this example). The option definition would then look like this:
|
|
174
174
|
flag :v, :verbose, 'be verbose (use up to three times)', multiple: true
|
175
175
|
--------------------------------------------------------------------------------
|
176
176
|
|
177
|
+
==== Skipping option parsing ====
|
178
|
+
|
179
|
+
If you want to skip option parsing for your command or subcommand, you can add
|
180
|
+
the `skip_option_parsing` method to your command definition and everything on your
|
181
|
+
command line after the command name will be passed to your command as arguments.
|
182
|
+
|
183
|
+
[source,ruby]
|
184
|
+
-------------------------------------------------------------------------------
|
185
|
+
command = Cri::Command.define do
|
186
|
+
name 'dostuff'
|
187
|
+
usage 'dostuff [args]'
|
188
|
+
aliases :ds, :stuff
|
189
|
+
summary 'does stuff'
|
190
|
+
description 'This command does a lot of stuff, but not option parsing.'
|
191
|
+
|
192
|
+
skip_option_parsing
|
193
|
+
|
194
|
+
run do |opts, args, cmd|
|
195
|
+
puts args.inspect
|
196
|
+
end
|
197
|
+
end
|
198
|
+
-------------------------------------------------------------------------------
|
199
|
+
|
200
|
+
When executing this command with `dostuff --some=value -f yes`, the `opts` hash
|
201
|
+
that is passed to your `run` block will be empty and the `args` array will be
|
202
|
+
`["--some=value", "-f", "yes"]`.
|
203
|
+
|
177
204
|
=== The run block ===
|
178
205
|
|
179
206
|
The last part of the command defines the execution itself:
|
data/cri.gemspec
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
$LOAD_PATH.unshift(File.expand_path('../lib/', __FILE__))
|
4
2
|
require 'cri/version'
|
5
3
|
|
@@ -17,6 +15,8 @@ Gem::Specification.new do |s|
|
|
17
15
|
s.files = Dir['[A-Z]*'] + Dir['{lib,test}/**/*'] + ['cri.gemspec']
|
18
16
|
s.require_paths = ['lib']
|
19
17
|
|
18
|
+
s.required_ruby_version = '~> 2.2'
|
19
|
+
|
20
20
|
s.add_dependency('colored', '~> 1.2')
|
21
21
|
|
22
22
|
s.add_development_dependency('bundler', '~> 1.6')
|
data/lib/cri/command.rb
CHANGED
@@ -92,6 +92,11 @@ module Cri
|
|
92
92
|
# command (ignored for commands with subcommands)
|
93
93
|
attr_accessor :block
|
94
94
|
|
95
|
+
# @return [Boolean] true if the command should skip option parsing and
|
96
|
+
# treat all options as arguments.
|
97
|
+
attr_accessor :all_opts_as_args
|
98
|
+
alias all_opts_as_args? all_opts_as_args
|
99
|
+
|
95
100
|
# Creates a new command using the DSL. If a string is given, the command
|
96
101
|
# will be defined using the string; if a block is given, the block will be
|
97
102
|
# used instead.
|
@@ -233,11 +238,11 @@ module Cri
|
|
233
238
|
commands = commands_named(name)
|
234
239
|
|
235
240
|
if commands.empty?
|
236
|
-
|
241
|
+
warn "#{self.name}: unknown command '#{name}'\n"
|
237
242
|
raise CriExitException.new(is_error: true)
|
238
243
|
elsif commands.size > 1
|
239
|
-
|
240
|
-
|
244
|
+
warn "#{self.name}: '#{name}' is ambiguous:"
|
245
|
+
warn " #{commands.map(&:name).sort.join(' ')}"
|
241
246
|
raise CriExitException.new(is_error: true)
|
242
247
|
else
|
243
248
|
commands[0]
|
@@ -271,7 +276,7 @@ module Cri
|
|
271
276
|
if default_subcommand_name
|
272
277
|
subcmd_name = default_subcommand_name
|
273
278
|
else
|
274
|
-
|
279
|
+
warn "#{name}: no command given"
|
275
280
|
raise CriExitException.new(is_error: true)
|
276
281
|
end
|
277
282
|
end
|
@@ -299,17 +304,22 @@ module Cri
|
|
299
304
|
#
|
300
305
|
# @return [void]
|
301
306
|
def run_this(opts_and_args, parent_opts = {})
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
307
|
+
if all_opts_as_args?
|
308
|
+
args = opts_and_args
|
309
|
+
global_opts = parent_opts
|
310
|
+
else
|
311
|
+
# Parse
|
312
|
+
parser = Cri::OptionParser.new(
|
313
|
+
opts_and_args, global_option_definitions
|
314
|
+
)
|
315
|
+
handle_parser_errors_while { parser.run }
|
316
|
+
local_opts = parser.options
|
317
|
+
global_opts = parent_opts.merge(parser.options)
|
318
|
+
args = parser.arguments
|
310
319
|
|
311
|
-
|
312
|
-
|
320
|
+
# Handle options
|
321
|
+
handle_options(local_opts)
|
322
|
+
end
|
313
323
|
|
314
324
|
# Execute
|
315
325
|
if block.nil?
|
@@ -352,6 +362,8 @@ module Cri
|
|
352
362
|
end
|
353
363
|
|
354
364
|
def partition(opts_and_args)
|
365
|
+
return [{}, opts_and_args.first, opts_and_args] if all_opts_as_args?
|
366
|
+
|
355
367
|
# Parse
|
356
368
|
delegate = Cri::Command::OptionParserPartitioningDelegate.new
|
357
369
|
parser = Cri::OptionParser.new(opts_and_args, global_option_definitions)
|
@@ -369,10 +381,10 @@ module Cri
|
|
369
381
|
def handle_parser_errors_while
|
370
382
|
yield
|
371
383
|
rescue Cri::OptionParser::IllegalOptionError => e
|
372
|
-
|
384
|
+
warn "#{name}: illegal option -- #{e}"
|
373
385
|
raise CriExitException.new(is_error: true)
|
374
386
|
rescue Cri::OptionParser::OptionRequiresAnArgumentError => e
|
375
|
-
|
387
|
+
warn "#{name}: option requires an argument -- #{e}"
|
376
388
|
raise CriExitException.new(is_error: true)
|
377
389
|
end
|
378
390
|
end
|
data/lib/cri/command_dsl.rb
CHANGED
@@ -98,6 +98,14 @@ module Cri
|
|
98
98
|
@command.hidden = true
|
99
99
|
end
|
100
100
|
|
101
|
+
# Skips option parsing for the command. Allows option-like arguments to be
|
102
|
+
# passed in, avoiding the {Cri::OptionParser} validation.
|
103
|
+
#
|
104
|
+
# @return [void]
|
105
|
+
def skip_option_parsing
|
106
|
+
@command.all_opts_as_args = true
|
107
|
+
end
|
108
|
+
|
101
109
|
# Adds a new option to the command. If a block is given, it will be
|
102
110
|
# executed when the option is successfully parsed.
|
103
111
|
#
|
data/lib/cri/version.rb
CHANGED
data/test/test_command.rb
CHANGED
@@ -632,5 +632,46 @@ module Cri
|
|
632
632
|
end
|
633
633
|
assert_equal "I am the subcommand!\n", out
|
634
634
|
end
|
635
|
+
|
636
|
+
def test_skip_option_parsing
|
637
|
+
command = Cri::Command.define do
|
638
|
+
name 'super'
|
639
|
+
skip_option_parsing
|
640
|
+
|
641
|
+
run do |_opts, args, _c|
|
642
|
+
puts "args=#{args.join(',')}"
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
out, _err = capture_io_while do
|
647
|
+
command.run(['--test', '-a', 'arg'])
|
648
|
+
end
|
649
|
+
|
650
|
+
assert_equal "args=--test,-a,arg\n", out
|
651
|
+
end
|
652
|
+
|
653
|
+
def test_subcommand_skip_option_parsing
|
654
|
+
super_cmd = Cri::Command.define do
|
655
|
+
name 'super'
|
656
|
+
|
657
|
+
option :a, :aaa, 'opt a', argument: :optional
|
658
|
+
end
|
659
|
+
|
660
|
+
super_cmd.define_command do
|
661
|
+
name 'sub'
|
662
|
+
|
663
|
+
skip_option_parsing
|
664
|
+
|
665
|
+
run do |opts, args, _c|
|
666
|
+
puts "opts=#{opts.inspect} args=#{args.join(',')}"
|
667
|
+
end
|
668
|
+
end
|
669
|
+
|
670
|
+
out, _err = capture_io_while do
|
671
|
+
super_cmd.run(['--aaa', 'test', 'sub', '--test', 'value'])
|
672
|
+
end
|
673
|
+
|
674
|
+
assert_equal "opts={:aaa=>\"test\"} args=--test,value\n", out
|
675
|
+
end
|
635
676
|
end
|
636
677
|
end
|
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.10.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: 2017-
|
11
|
+
date: 2017-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored
|
@@ -48,6 +48,7 @@ extra_rdoc_files:
|
|
48
48
|
- README.adoc
|
49
49
|
- NEWS.md
|
50
50
|
files:
|
51
|
+
- CODE_OF_CONDUCT.md
|
51
52
|
- Gemfile
|
52
53
|
- Gemfile.lock
|
53
54
|
- LICENSE
|
@@ -92,9 +93,9 @@ require_paths:
|
|
92
93
|
- lib
|
93
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
95
|
requirements:
|
95
|
-
- - "
|
96
|
+
- - "~>"
|
96
97
|
- !ruby/object:Gem::Version
|
97
|
-
version: '
|
98
|
+
version: '2.2'
|
98
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
100
|
requirements:
|
100
101
|
- - ">="
|
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
105
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.6.
|
106
|
+
rubygems_version: 2.6.14
|
106
107
|
signing_key:
|
107
108
|
specification_version: 4
|
108
109
|
summary: a library for building easy-to-use command-line tools
|