New upstream version 4.4.4

parent f41ca768
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 1.9
# not Ruby 1.9.3 compatible
Style/PercentLiteralDelimiters:
Enabled: false
# Offense count: 5
Encoding:
Enabled: false
......@@ -23,10 +30,10 @@ Style/NumericLiteralPrefix:
Style/MethodMissing:
Enabled: false
Style/SpaceInsideStringInterpolation:
Layout/SpaceInsideStringInterpolation:
Enabled: false
Style/MultilineOperationIndentation:
Layout/MultilineOperationIndentation:
Enabled: false
Style/EmptyMethod:
......
......@@ -6,7 +6,7 @@
# versions of RuboCop, may require this file to be generated again.
# Offense count: 2
Lint/Eval:
Security/Eval:
Enabled: false
# Offense count: 2
......
language: ruby
cache: bundler
before_install:
- gem update --system
- gem update bundler
......@@ -6,7 +7,8 @@ rvm:
- 1.9.3
- 2.0.0
- 2.1.10
- 2.2.6
- 2.3.3
- 2.4.0
- 2.2.9
- 2.3.6
- 2.4.3
- 2.5.0
- jruby-19mode
=== 4.4.4 / 2018-01-18
* Fix deprecated constant warnings on Ruby 2.5. (@mattbrictson)
=== 4.4.3 / 2016-12-28
* Fix deprecated constant warnings on Ruby 2.4.
......
[<img src="https://secure.travis-ci.org/commander-rb/commander.png?branch=master" alt="Build Status" />](http://travis-ci.org/commander-rb/commander)
[![Inline docs](http://inch-ci.org/github/commander-rb/commander.png)](http://inch-ci.org/github/commander-rb/commander)
[<img src="https://api.travis-ci.org/commander-rb/commander.svg" alt="Build Status" />](http://travis-ci.org/commander-rb/commander)
[![Inline docs](http://inch-ci.org/github/commander-rb/commander.svg)](http://inch-ci.org/github/commander-rb/commander)
# Commander
......@@ -339,6 +339,21 @@ $ foo install gem
# => installing to
```
### Long descriptions
If you need to have a long command description, keep your short description under `summary`, and consider multi-line strings for `description`:
```ruby
program :summary, 'Stupid command that prints foo or bar.'
program :description, %q(
#{c.summary}
More information about that stupid command that prints foo or bar.
And more
)
```
### Additional Global Help
Arbitrary help can be added using the following `#program` symbol:
......
# -*- encoding: utf-8 -*-
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'commander/version'
......@@ -26,6 +27,6 @@ Gem::Specification.new do |s|
s.add_development_dependency('rubocop', '~> 0.41.1')
s.add_development_dependency('json', '< 2.0')
else
s.add_development_dependency('rubocop', '~> 0.46')
s.add_development_dependency('rubocop', '~> 0.49.1')
end
end
......@@ -324,22 +324,45 @@ module Commander
# Implements ask_for_CLASS methods.
module AskForClass
DEPRECATED_CONSTANTS = [:Config, :TimeoutError, :MissingSourceFile, :NIL, :TRUE, :FALSE, :Fixnum, :Bignum].freeze
# All special cases in HighLine::Question#convert, except those that implement #parse
(
[Float, Integer, String, Symbol, Regexp, Array, File, Pathname] +
# All Classes that respond to #parse
# Ignore constants that trigger deprecation warnings
(Object.constants - DEPRECATED_CONSTANTS).map do |const|
Object.const_get(const)
end.select do |const|
const.class == Class && const.respond_to?(:parse)
end
).each do |klass|
DEPRECATED_CONSTANTS = [:Config, :TimeoutError, :MissingSourceFile, :NIL, :TRUE, :FALSE, :Fixnum, :Bignum, :Data].freeze
# define methods for common classes
[Float, Integer, String, Symbol, Regexp, Array, File, Pathname].each do |klass|
define_method "ask_for_#{klass.to_s.downcase}" do |prompt|
$terminal.ask(prompt, klass)
end
end
def method_missing(method_name, *arguments, &block)
if method_name.to_s =~ /^ask_for_(.*)/
if arguments.count != 1
fail ArgumentError, "wrong number of arguments (given #{arguments.count}, expected 1)"
end
prompt = arguments.first
requested_class = Regexp.last_match[1]
# All Classes that respond to #parse
# Ignore constants that trigger deprecation warnings
available_classes = (Object.constants - DEPRECATED_CONSTANTS).map do |const|
Object.const_get(const)
end.select do |const|
const.class == Class && const.respond_to?(:parse)
end
klass = available_classes.find { |k| k.to_s.downcase == requested_class }
if klass
$terminal.ask(prompt, klass)
else
super
end
else
super
end
end
def respond_to_missing?(method_name, include_private = false)
method_name.to_s.start_with?('ask_for_') || super
end
end
##
......
module Commander
VERSION = '4.4.3'.freeze
VERSION = '4.4.4'.freeze
end
......@@ -6,8 +6,49 @@ describe Commander::Methods do
expect(subject.ancestors).to include(Commander::UI)
end
it 'includes Commander::UI::AskForClass' do
expect(subject.ancestors).to include(Commander::UI::AskForClass)
describe 'AskForClass' do
it 'includes Commander::UI::AskForClass' do
expect(subject.ancestors).to include(Commander::UI::AskForClass)
end
describe 'defining methods' do
let(:terminal) { double }
before do
allow(terminal).to receive(:ask)
$_old_terminal = $terminal
$terminal = terminal
end
after do
$terminal = $_old_terminal
end
subject do
Class.new do
include Commander::UI::AskForClass
end.new
end
it 'defines common "ask_for_*" methods' do
expect(subject.respond_to?(:ask_for_float)).to be_truthy
end
it 'responds to "ask_for_*" methods for classes that implement #parse' do
expect(subject.respond_to?(:ask_for_datetime)).to be_truthy
end
it 'fails "ask_for_*" method invocations without a prompt' do
expect do
subject.ask_for_datetime
end.to raise_error(ArgumentError)
end
it 'implements "ask_for_*"' do
expect(terminal).to receive(:ask)
subject.ask_for_datetime('hi')
end
end
end
it 'includes Commander::Delegates' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment