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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42a611aea2f4ef126558c77832d3f87e4c7769ee
4
- data.tar.gz: 4629089940c31510094b05bafef780756d72f2db
3
+ metadata.gz: 7c7acd3557015c65b10c166ddd982ff09a9e9439
4
+ data.tar.gz: 1084f157713632392659284ae92b39b85f5c45dd
5
5
  SHA512:
6
- metadata.gz: 5722bead0775cc5d35b658d60318c7b530590681f751dcfb51b9bf6cfd9c0d065387237d7906b8c4163a324d4e1df288f76bcac6fa4fb37775336b8c2908feff
7
- data.tar.gz: 67a2d794fa2206fd4487068cb4ffe6e3876c8c9c1b49951b180d7bc62ae4bc375db1a063fbebab89a5aac6bc3e314bdb6e41ced98bbca7e6838424514aa2a17d
6
+ metadata.gz: 672ba33c779d549ffb422125dc480fa81f33f04ece3753f1f2294de9389d1ff6b91607ad3340db86cdef47e80282cbbd6e61d06fadd5f1c4e6e0a42115a1470b
7
+ data.tar.gz: 250a1fc1938e2be8090e772dddd2b3f3ca83e7c9f899cf2ace594750b5368b2e2a9ed538fe618ae863fbb88829c8bd116a1f1185fc5e88593fea4ab1aa7d0c3d
data/Gemfile CHANGED
@@ -7,3 +7,4 @@ gem 'rake'
7
7
  gem 'minitest'
8
8
  gem 'yard'
9
9
  gem 'asciidoctor'
10
+ gem 'rubocop'
@@ -1,37 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cri (2.6.1)
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 (0.1.4)
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.7.0)
13
- multi_json (~> 1.3)
14
- rest-client
15
- simplecov (>= 0.7)
16
- term-ansicolor
17
- thor
18
- docile (1.1.3)
19
- mime-types (2.3)
20
- minitest (5.3.4)
21
- multi_json (1.10.1)
22
- rake (10.3.2)
23
- rest-client (1.6.7)
24
- mime-types (>= 1.16)
25
- simplecov (0.8.2)
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
- multi_json
28
- simplecov-html (~> 0.8.0)
29
- simplecov-html (0.8.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.3.0)
34
- yard (0.8.7.4)
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Denis Defreyne and contributors
1
+ Copyright (c) 2015 Denis Defreyne and contributors
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
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
 
@@ -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-pages.github.io/github/ddfreyne/cri/[image:http://inch-pages.github.io/github/ddfreyne/cri.svg[]]
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 :test do
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
@@ -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 = Dir['[A-Z]*'] +
18
- Dir['{lib,test}/**/*'] +
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 = [ '--main', 'README.adoc' ]
27
- s.extra_rdoc_files = [ 'LICENSE', 'README.adoc', 'NEWS.md' ]
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'
@@ -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
@@ -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(key, value, option_parser)
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 ? [ string, filename ] : [ string ]
97
+ args = filename ? [string, filename] : [string]
102
98
  dsl.instance_eval(*args)
103
- elsif [ -1, 0 ].include? block.arity
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
- self.define(File.read(filename))
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
- self.define(File.read(filename))
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 [ -1, 0 ].include? block.arity
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 [ -1, 0 ].include? block.arity
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
- self.add_command(cmd)
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 [ cmd ] if found
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? && !self.block.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 = self.command_named(subcmd_name)
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, self.global_option_definitions)
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 self.block.nil?
295
- raise NotImplementedError,
296
- "No implementation available for '#{self.name}'"
290
+ if block.nil?
291
+ fail NotImplementedError,
292
+ "No implementation available for '#{name}'"
297
293
  end
298
- self.block.call(global_opts, args, self)
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
- self.name <=> other.name
316
+ name <=> other.name
321
317
  end
322
318
 
323
- private
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
- begin
351
- block.call
352
- rescue Cri::OptionParser::IllegalOptionError => e
353
- $stderr.puts "#{name}: illegal option -- #{e}"
354
- exit 1
355
- rescue Cri::OptionParser::OptionRequiresAnArgumentError => e
356
- $stderr.puts "#{name}: option requires an argument -- #{e}"
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