cri 2.6.1 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +46 -21
- data/LICENSE +1 -1
- data/NEWS.md +12 -0
- data/README.adoc +1 -1
- data/Rakefile +7 -2
- data/cri.gemspec +5 -7
- data/lib/cri.rb +0 -2
- data/lib/cri/argument_array.rb +0 -4
- data/lib/cri/command.rb +31 -40
- data/lib/cri/command_dsl.rb +28 -18
- data/lib/cri/command_runner.rb +2 -6
- data/lib/cri/commands/basic_help.rb +2 -2
- data/lib/cri/commands/basic_root.rb +1 -1
- data/lib/cri/core_ext.rb +3 -1
- data/lib/cri/core_ext/string.rb +28 -30
- data/lib/cri/help_renderer.rb +105 -23
- data/lib/cri/option_parser.rb +13 -17
- data/lib/cri/platform.rb +1 -5
- data/lib/cri/string_formatter.rb +14 -9
- data/lib/cri/version.rb +1 -3
- data/test/helper.rb +38 -38
- data/test/test_argument_array.rb +7 -7
- data/test/test_base.rb +4 -4
- data/test/test_basic_help.rb +47 -47
- data/test/test_basic_root.rb +10 -10
- data/test/test_command.rb +424 -347
- data/test/test_command_dsl.rb +174 -150
- data/test/test_command_runner.rb +22 -23
- data/test/test_option_parser.rb +212 -224
- data/test/test_string_formatter.rb +97 -82
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c7acd3557015c65b10c166ddd982ff09a9e9439
|
4
|
+
data.tar.gz: 1084f157713632392659284ae92b39b85f5c45dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 672ba33c779d549ffb422125dc480fa81f33f04ece3753f1f2294de9389d1ff6b91607ad3340db86cdef47e80282cbbd6e61d06fadd5f1c4e6e0a42115a1470b
|
7
|
+
data.tar.gz: 250a1fc1938e2be8090e772dddd2b3f3ca83e7c9f899cf2ace594750b5368b2e2a9ed538fe618ae863fbb88829c8bd116a1f1185fc5e88593fea4ab1aa7d0c3d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,37 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cri (2.
|
4
|
+
cri (2.7.0)
|
5
5
|
colored (~> 1.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
asciidoctor (
|
10
|
+
asciidoctor (1.5.2)
|
11
|
+
ast (2.0.0)
|
12
|
+
astrolabe (1.3.0)
|
13
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
11
14
|
colored (1.2)
|
12
|
-
coveralls (0.
|
13
|
-
|
14
|
-
rest-client
|
15
|
-
simplecov (
|
16
|
-
term-ansicolor
|
17
|
-
thor
|
18
|
-
docile (1.1.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
15
|
+
coveralls (0.8.1)
|
16
|
+
json (~> 1.8)
|
17
|
+
rest-client (>= 1.6.8, < 2)
|
18
|
+
simplecov (~> 0.10.0)
|
19
|
+
term-ansicolor (~> 1.3)
|
20
|
+
thor (~> 0.19.1)
|
21
|
+
docile (1.1.5)
|
22
|
+
domain_name (0.5.24)
|
23
|
+
unf (>= 0.0.5, < 1.0.0)
|
24
|
+
http-cookie (1.0.2)
|
25
|
+
domain_name (~> 0.5)
|
26
|
+
json (1.8.2)
|
27
|
+
mime-types (2.5)
|
28
|
+
minitest (5.6.1)
|
29
|
+
netrc (0.10.3)
|
30
|
+
parser (2.2.2.2)
|
31
|
+
ast (>= 1.1, < 3.0)
|
32
|
+
powerpack (0.1.0)
|
33
|
+
rainbow (2.0.0)
|
34
|
+
rake (10.4.2)
|
35
|
+
rest-client (1.8.0)
|
36
|
+
http-cookie (>= 1.0.2, < 2.0)
|
37
|
+
mime-types (>= 1.16, < 3.0)
|
38
|
+
netrc (~> 0.7)
|
39
|
+
rubocop (0.30.1)
|
40
|
+
astrolabe (~> 1.3)
|
41
|
+
parser (>= 2.2.2.1, < 3.0)
|
42
|
+
powerpack (~> 0.1)
|
43
|
+
rainbow (>= 1.99.1, < 3.0)
|
44
|
+
ruby-progressbar (~> 1.4)
|
45
|
+
ruby-progressbar (1.7.5)
|
46
|
+
simplecov (0.10.0)
|
26
47
|
docile (~> 1.1.0)
|
27
|
-
|
28
|
-
simplecov-html (~> 0.
|
29
|
-
simplecov-html (0.
|
48
|
+
json (~> 1.8)
|
49
|
+
simplecov-html (~> 0.10.0)
|
50
|
+
simplecov-html (0.10.0)
|
30
51
|
term-ansicolor (1.3.0)
|
31
52
|
tins (~> 1.0)
|
32
53
|
thor (0.19.1)
|
33
|
-
tins (1.
|
34
|
-
|
54
|
+
tins (1.5.1)
|
55
|
+
unf (0.1.4)
|
56
|
+
unf_ext
|
57
|
+
unf_ext (0.0.7.1)
|
58
|
+
yard (0.8.7.6)
|
35
59
|
|
36
60
|
PLATFORMS
|
37
61
|
ruby
|
@@ -43,4 +67,5 @@ DEPENDENCIES
|
|
43
67
|
cri!
|
44
68
|
minitest
|
45
69
|
rake
|
70
|
+
rubocop
|
46
71
|
yard
|
data/LICENSE
CHANGED
data/NEWS.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
Cri News
|
2
2
|
========
|
3
3
|
|
4
|
+
2.7.0
|
5
|
+
-----
|
6
|
+
|
7
|
+
Features:
|
8
|
+
|
9
|
+
* Added support for hidden options (#43, #44) [Bart Mesuere]
|
10
|
+
|
11
|
+
Enhancements:
|
12
|
+
|
13
|
+
* Added option values to help output (#37, #40, #41)
|
14
|
+
* Made option descriptions wrap (#36, #45) [Bart Mesuere]
|
15
|
+
|
4
16
|
2.6.1
|
5
17
|
-----
|
6
18
|
|
data/README.adoc
CHANGED
@@ -4,7 +4,7 @@ link:http://rubygems.org/gems/cri[image:http://img.shields.io/gem/v/cri.svg[]]
|
|
4
4
|
link:https://travis-ci.org/ddfreyne/cri[image:http://img.shields.io/travis/ddfreyne/cri.svg[]]
|
5
5
|
link:https://coveralls.io/r/ddfreyne/cri[image:http://img.shields.io/coveralls/ddfreyne/cri.svg[]]
|
6
6
|
link:https://codeclimate.com/github/ddfreyne/cri[image:http://img.shields.io/codeclimate/github/ddfreyne/cri.svg[]]
|
7
|
-
link:http://inch-
|
7
|
+
link:http://inch-ci.org/github/ddfreyne/cri/[image:http://inch-ci.org/github/ddfreyne/cri.svg[]]
|
8
8
|
|
9
9
|
Cri is a library for building easy-to-use commandline tools with support for
|
10
10
|
nested commands.
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoing: utf-8
|
2
2
|
|
3
3
|
require 'rake/testtask'
|
4
|
+
require 'rubocop/rake_task'
|
4
5
|
require 'yard'
|
5
6
|
|
6
7
|
YARD::Rake::YardocTask.new(:doc) do |yard|
|
@@ -9,11 +10,11 @@ YARD::Rake::YardocTask.new(:doc) do |yard|
|
|
9
10
|
'--markup', 'markdown',
|
10
11
|
'--readme', 'README.adoc',
|
11
12
|
'--files', 'NEWS.md,LICENSE',
|
12
|
-
'--output-dir', 'doc/yardoc'
|
13
|
+
'--output-dir', 'doc/yardoc'
|
13
14
|
]
|
14
15
|
end
|
15
16
|
|
16
|
-
task :
|
17
|
+
task :test_unit do
|
17
18
|
require './test/helper.rb'
|
18
19
|
|
19
20
|
FileList['./test/**/test_*.rb', './test/**/*_spec.rb'].each do |fn|
|
@@ -21,4 +22,8 @@ task :test do
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
25
|
+
RuboCop::RakeTask.new(:test_style)
|
26
|
+
|
27
|
+
task :test => [:test_unit, :test_style]
|
28
|
+
|
24
29
|
task :default => :test
|
data/cri.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'cri/version'
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'cri'
|
8
8
|
s.version = Cri::VERSION
|
9
|
-
s.homepage = 'http://stoneship.org/software/cri/' # TODO CREATE A WEB SITE YOU SILLY PERSON
|
9
|
+
s.homepage = 'http://stoneship.org/software/cri/' # TODO: CREATE A WEB SITE YOU SILLY PERSON
|
10
10
|
s.summary = 'a library for building easy-to-use commandline tools'
|
11
11
|
s.description = 'Cri allows building easy-to-use commandline interfaces with support for subcommands.'
|
12
12
|
s.license = 'MIT'
|
@@ -14,15 +14,13 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.author = 'Denis Defreyne'
|
15
15
|
s.email = 'denis.defreyne@stoneship.org'
|
16
16
|
|
17
|
-
s.files
|
18
|
-
|
19
|
-
[ 'cri.gemspec' ]
|
20
|
-
s.require_paths = [ 'lib' ]
|
17
|
+
s.files = Dir['[A-Z]*'] + Dir['{lib,test}/**/*'] + ['cri.gemspec']
|
18
|
+
s.require_paths = ['lib']
|
21
19
|
|
22
20
|
s.add_dependency('colored', '~> 1.2')
|
23
21
|
|
24
22
|
s.add_development_dependency('bundler', '~> 1.6')
|
25
23
|
|
26
|
-
s.rdoc_options = [
|
27
|
-
s.extra_rdoc_files = [
|
24
|
+
s.rdoc_options = ['--main', 'README.adoc']
|
25
|
+
s.extra_rdoc_files = ['LICENSE', 'README.adoc', 'NEWS.md']
|
28
26
|
end
|
data/lib/cri.rb
CHANGED
@@ -5,7 +5,6 @@ require 'cri/version'
|
|
5
5
|
# The namespace for Cri, a library for building easy-to-use commandline tools
|
6
6
|
# with support for nested commands.
|
7
7
|
module Cri
|
8
|
-
|
9
8
|
# A generic error class for all Cri-specific errors.
|
10
9
|
class Error < ::StandardError
|
11
10
|
end
|
@@ -27,7 +26,6 @@ module Cri
|
|
27
26
|
autoload 'HelpRenderer', 'cri/help_renderer'
|
28
27
|
autoload 'OptionParser', 'cri/option_parser'
|
29
28
|
autoload 'Platform', 'cri/platform'
|
30
|
-
|
31
29
|
end
|
32
30
|
|
33
31
|
require 'set'
|
data/lib/cri/argument_array.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Cri
|
4
|
-
|
5
4
|
# Represents an array of arguments. It is an array that strips separator
|
6
5
|
# arguments (`--`) but provides a `#raw` method to get the raw arguments
|
7
6
|
# array, i.e. an array that includes the separator `--` arguments.
|
8
7
|
class ArgumentArray < Array
|
9
|
-
|
10
8
|
# Initializes the array using the given raw arguments.
|
11
9
|
#
|
12
10
|
# @param [Array<String>] raw_arguments A list of raw arguments, i.e.
|
@@ -21,7 +19,5 @@ module Cri
|
|
21
19
|
def raw
|
22
20
|
@raw_arguments
|
23
21
|
end
|
24
|
-
|
25
22
|
end
|
26
|
-
|
27
23
|
end
|
data/lib/cri/command.rb
CHANGED
@@ -1,18 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Cri
|
4
|
-
|
5
4
|
# Cri::Command represents a command that can be executed on the commandline.
|
6
5
|
# It is also used for the commandline tool itself.
|
7
6
|
class Command
|
8
|
-
|
9
7
|
# Delegate used for partitioning the list of arguments and options. This
|
10
8
|
# delegate will stop the parser as soon as the first argument, i.e. the
|
11
9
|
# command, is found.
|
12
10
|
#
|
13
11
|
# @api private
|
14
12
|
class OptionParserPartitioningDelegate
|
15
|
-
|
16
13
|
# Returns the last parsed argument, which, in this case, will be the
|
17
14
|
# first argument, which will be either nil or the command name.
|
18
15
|
#
|
@@ -28,7 +25,7 @@ module Cri
|
|
28
25
|
# @param [Cri::OptionParser] option_parser The option parser
|
29
26
|
#
|
30
27
|
# @return [void]
|
31
|
-
def option_added(
|
28
|
+
def option_added(_key, _value, _option_parser)
|
32
29
|
end
|
33
30
|
|
34
31
|
# Called when an argument is parsed.
|
@@ -42,7 +39,6 @@ module Cri
|
|
42
39
|
@last_argument = argument
|
43
40
|
option_parser.stop
|
44
41
|
end
|
45
|
-
|
46
42
|
end
|
47
43
|
|
48
44
|
# @return [Cri::Command, nil] This command’s supercommand, or nil if the
|
@@ -95,12 +91,12 @@ module Cri
|
|
95
91
|
# @param [String, nil] filename The filename corresponding to the string parameter (only useful if a string is given)
|
96
92
|
#
|
97
93
|
# @return [Cri::Command] The newly defined command
|
98
|
-
def self.define(string=nil, filename=nil, &block)
|
94
|
+
def self.define(string = nil, filename = nil, &block)
|
99
95
|
dsl = Cri::CommandDSL.new
|
100
96
|
if string
|
101
|
-
args = filename ? [
|
97
|
+
args = filename ? [string, filename] : [string]
|
102
98
|
dsl.instance_eval(*args)
|
103
|
-
elsif [
|
99
|
+
elsif [-1, 0].include? block.arity
|
104
100
|
dsl.instance_eval(&block)
|
105
101
|
else
|
106
102
|
block.call(dsl)
|
@@ -115,7 +111,7 @@ module Cri
|
|
115
111
|
# @return [Cri::Command] A basic root command
|
116
112
|
def self.new_basic_root
|
117
113
|
filename = File.dirname(__FILE__) + '/commands/basic_root.rb'
|
118
|
-
|
114
|
+
define(File.read(filename))
|
119
115
|
end
|
120
116
|
|
121
117
|
# Returns a new command that implements showing help.
|
@@ -123,7 +119,7 @@ module Cri
|
|
123
119
|
# @return [Cri::Command] A basic help command
|
124
120
|
def self.new_basic_help
|
125
121
|
filename = File.dirname(__FILE__) + '/commands/basic_help.rb'
|
126
|
-
|
122
|
+
define(File.read(filename))
|
127
123
|
end
|
128
124
|
|
129
125
|
def initialize
|
@@ -141,7 +137,7 @@ module Cri
|
|
141
137
|
# @return [Cri::Command] The command itself
|
142
138
|
def modify(&block)
|
143
139
|
dsl = Cri::CommandDSL.new(self)
|
144
|
-
if [
|
140
|
+
if [-1, 0].include? block.arity
|
145
141
|
dsl.instance_eval(&block)
|
146
142
|
else
|
147
143
|
block.call(dsl)
|
@@ -174,11 +170,11 @@ module Cri
|
|
174
170
|
# should be set (yet)
|
175
171
|
#
|
176
172
|
# @return [Cri::Command] The subcommand
|
177
|
-
def define_command(name=nil, &block)
|
173
|
+
def define_command(name = nil, &block)
|
178
174
|
# Execute DSL
|
179
175
|
dsl = Cri::CommandDSL.new
|
180
176
|
dsl.name name unless name.nil?
|
181
|
-
if [
|
177
|
+
if [-1, 0].include? block.arity
|
182
178
|
dsl.instance_eval(&block)
|
183
179
|
else
|
184
180
|
block.call(dsl)
|
@@ -186,7 +182,7 @@ module Cri
|
|
186
182
|
|
187
183
|
# Create command
|
188
184
|
cmd = dsl.command
|
189
|
-
|
185
|
+
add_command(cmd)
|
190
186
|
cmd
|
191
187
|
end
|
192
188
|
|
@@ -200,7 +196,7 @@ module Cri
|
|
200
196
|
# Find by exact name or alias
|
201
197
|
@commands.each do |cmd|
|
202
198
|
found = cmd.name == name || cmd.aliases.include?(name)
|
203
|
-
return [
|
199
|
+
return [cmd] if found
|
204
200
|
end
|
205
201
|
|
206
202
|
# Find by approximation
|
@@ -242,12 +238,12 @@ module Cri
|
|
242
238
|
# supercommand
|
243
239
|
#
|
244
240
|
# @return [void]
|
245
|
-
def run(opts_and_args, parent_opts={})
|
241
|
+
def run(opts_and_args, parent_opts = {})
|
246
242
|
# Parse up to command name
|
247
243
|
stuff = partition(opts_and_args)
|
248
244
|
opts_before_subcmd, subcmd_name, opts_and_args_after_subcmd = *stuff
|
249
245
|
|
250
|
-
if subcommands.empty? || (subcmd_name.nil? && !
|
246
|
+
if subcommands.empty? || (subcmd_name.nil? && !block.nil?)
|
251
247
|
run_this(opts_and_args, parent_opts)
|
252
248
|
else
|
253
249
|
# Handle options
|
@@ -258,7 +254,7 @@ module Cri
|
|
258
254
|
$stderr.puts "#{name}: no command given"
|
259
255
|
exit 1
|
260
256
|
end
|
261
|
-
subcommand =
|
257
|
+
subcommand = command_named(subcmd_name)
|
262
258
|
|
263
259
|
# Run
|
264
260
|
subcommand.run(opts_and_args_after_subcmd, opts_before_subcmd)
|
@@ -278,10 +274,10 @@ module Cri
|
|
278
274
|
# block
|
279
275
|
#
|
280
276
|
# @return [void]
|
281
|
-
def run_this(opts_and_args, parent_opts={})
|
277
|
+
def run_this(opts_and_args, parent_opts = {})
|
282
278
|
# Parse
|
283
279
|
parser = Cri::OptionParser.new(
|
284
|
-
opts_and_args,
|
280
|
+
opts_and_args, global_option_definitions)
|
285
281
|
handle_parser_errors_while { parser.run }
|
286
282
|
local_opts = parser.options
|
287
283
|
global_opts = parent_opts.merge(parser.options)
|
@@ -291,11 +287,11 @@ module Cri
|
|
291
287
|
handle_options(local_opts)
|
292
288
|
|
293
289
|
# Execute
|
294
|
-
if
|
295
|
-
|
296
|
-
|
290
|
+
if block.nil?
|
291
|
+
fail NotImplementedError,
|
292
|
+
"No implementation available for '#{name}'"
|
297
293
|
end
|
298
|
-
|
294
|
+
block.call(global_opts, args, self)
|
299
295
|
end
|
300
296
|
|
301
297
|
# @return [String] The help text for this command
|
@@ -305,7 +301,7 @@ module Cri
|
|
305
301
|
#
|
306
302
|
# @option params [IO] :io ($stdout) the IO the help text is intended for.
|
307
303
|
# This influences the decision to enable/disable colored output.
|
308
|
-
def help(params={})
|
304
|
+
def help(params = {})
|
309
305
|
HelpRenderer.new(self, params).render
|
310
306
|
end
|
311
307
|
|
@@ -317,10 +313,10 @@ module Cri
|
|
317
313
|
#
|
318
314
|
# @see Object<=>
|
319
315
|
def <=>(other)
|
320
|
-
|
316
|
+
name <=> other.name
|
321
317
|
end
|
322
318
|
|
323
|
-
|
319
|
+
private
|
324
320
|
|
325
321
|
def handle_options(opts)
|
326
322
|
opts.each_pair do |key, value|
|
@@ -336,28 +332,23 @@ module Cri
|
|
336
332
|
parser = Cri::OptionParser.new(opts_and_args, global_option_definitions)
|
337
333
|
parser.delegate = delegate
|
338
334
|
handle_parser_errors_while { parser.run }
|
339
|
-
parser
|
340
335
|
|
341
336
|
# Extract
|
342
337
|
[
|
343
338
|
parser.options,
|
344
339
|
delegate.last_argument,
|
345
|
-
parser.unprocessed_arguments_and_options
|
340
|
+
parser.unprocessed_arguments_and_options,
|
346
341
|
]
|
347
342
|
end
|
348
343
|
|
349
344
|
def handle_parser_errors_while(&block)
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
exit 1
|
358
|
-
end
|
345
|
+
block.call
|
346
|
+
rescue Cri::OptionParser::IllegalOptionError => e
|
347
|
+
$stderr.puts "#{name}: illegal option -- #{e}"
|
348
|
+
exit 1
|
349
|
+
rescue Cri::OptionParser::OptionRequiresAnArgumentError => e
|
350
|
+
$stderr.puts "#{name}: option requires an argument -- #{e}"
|
351
|
+
exit 1
|
359
352
|
end
|
360
|
-
|
361
353
|
end
|
362
|
-
|
363
354
|
end
|