commander 4.4.6 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -6
  3. data/.rubocop_todo.yml +4 -4
  4. data/.travis.yml +7 -8
  5. data/Gemfile +2 -0
  6. data/History.rdoc +25 -0
  7. data/README.md +6 -6
  8. data/Rakefile +3 -1
  9. data/bin/commander +2 -1
  10. data/commander.gemspec +13 -10
  11. data/lib/commander.rb +2 -0
  12. data/lib/commander/blank.rb +2 -0
  13. data/lib/commander/command.rb +10 -5
  14. data/lib/commander/configure.rb +2 -0
  15. data/lib/commander/core_ext.rb +2 -0
  16. data/lib/commander/core_ext/array.rb +3 -1
  17. data/lib/commander/core_ext/object.rb +2 -0
  18. data/lib/commander/delegates.rb +3 -1
  19. data/lib/commander/help_formatters.rb +3 -1
  20. data/lib/commander/help_formatters/base.rb +2 -0
  21. data/lib/commander/help_formatters/terminal.rb +7 -1
  22. data/lib/commander/help_formatters/terminal/command_help.erb +6 -6
  23. data/lib/commander/help_formatters/terminal/help.erb +7 -7
  24. data/lib/commander/help_formatters/terminal_compact.rb +7 -1
  25. data/lib/commander/import.rb +2 -0
  26. data/lib/commander/methods.rb +4 -2
  27. data/lib/commander/platform.rb +2 -0
  28. data/lib/commander/runner.rb +44 -36
  29. data/lib/commander/user_interaction.rb +27 -21
  30. data/lib/commander/version.rb +3 -1
  31. data/spec/command_spec.rb +29 -0
  32. data/spec/configure_spec.rb +2 -0
  33. data/spec/core_ext/array_spec.rb +3 -1
  34. data/spec/core_ext/object_spec.rb +2 -0
  35. data/spec/help_formatters/terminal_compact_spec.rb +2 -0
  36. data/spec/help_formatters/terminal_spec.rb +2 -0
  37. data/spec/methods_spec.rb +5 -3
  38. data/spec/runner_spec.rb +123 -8
  39. data/spec/spec_helper.rb +15 -4
  40. data/spec/ui_spec.rb +4 -2
  41. metadata +34 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 584705d6b59c75d49df6d2369763f91b5a5dbc5013575dbb2be575983b040f60
4
- data.tar.gz: 0bab3911300bcc194406717c08ab1718608c86fe62703f0219a16a645bded947
3
+ metadata.gz: f91f8a37c32e7971823b150b8b89d7f992a6971c66351ae7527b27cdbf0926db
4
+ data.tar.gz: bcd3c3131f145cea800da48c7231a6d3b0b892eed9107fd64dac52b03da2f44b
5
5
  SHA512:
6
- metadata.gz: 1bb1d5703d53f0c6a140e7f24e0d4c9f0e80283425b2daf49d80da554a78122d4eb731bb9ee817c11e0636732938ffab81367312f599b40c3c8f8dc036ab9604
7
- data.tar.gz: 1da0b8c354a4b0fc744e170c6d6e3393ddbb759ae9fecf50cf06274ee1611dd48d1f9c69e0414c3b28d2d810d56e0a6348c17eec3c58b084dd14f594a7f9a3b4
6
+ metadata.gz: e9c808ed77df3bc880db7a790ca207b6b6beb98be447f27f55fdcd25dc32c1131bb06d6d69e47de076b590ff4182e250b6b752b3bf2439ef0f94a2168d3acc40
7
+ data.tar.gz: fcfb725ce863649b098cea94314d612a5b755abd996199ed63a3e8018baef804790b8ce57e02229fed75c3247597f2030aab3bec47d0a544eb81586c45548722
data/.rubocop.yml CHANGED
@@ -1,18 +1,20 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 1.9
4
+ TargetRubyVersion: 2.4
5
+ NewCops: enable
6
+ SuggestExtensions: false
5
7
 
6
8
  # not Ruby 1.9.3 compatible
7
9
  Style/PercentLiteralDelimiters:
8
10
  Enabled: false
9
11
 
10
- # Offense count: 5
11
- Encoding:
12
- Enabled: false
12
+ # Enforce trailing comma after last item of multiline arrays.
13
+ Style/TrailingCommaInArrayLiteral:
14
+ EnforcedStyleForMultiline: comma
13
15
 
14
16
  # Enforce trailing comma after last item of multiline hashes.
15
- Style/TrailingCommaInLiteral:
17
+ Style/TrailingCommaInHashLiteral:
16
18
  EnforcedStyleForMultiline: comma
17
19
 
18
20
  Metrics/BlockLength:
@@ -27,7 +29,7 @@ Style/ParallelAssignment:
27
29
  Style/NumericLiteralPrefix:
28
30
  EnforcedOctalStyle: zero_only
29
31
 
30
- Style/MethodMissing:
32
+ Style/MissingRespondToMissing:
31
33
  Enabled: false
32
34
 
33
35
  Layout/SpaceInsideStringInterpolation:
@@ -42,3 +44,21 @@ Style/EmptyMethod:
42
44
  Metrics/ModuleLength:
43
45
  CountComments: false # count full line comments?
44
46
  Max: 150
47
+
48
+ Lint/EmptyBlock:
49
+ Enabled: false
50
+
51
+ Style/FormatStringToken:
52
+ Enabled: false
53
+
54
+ Style/MixinUsage:
55
+ Enabled: false
56
+
57
+ Lint/ErbNewArguments:
58
+ Enabled: false
59
+
60
+ Style/DocumentDynamicEvalDefinition:
61
+ Enabled: false
62
+
63
+ Naming/HeredocDelimiterNaming:
64
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -10,12 +10,12 @@ Security/Eval:
10
10
  Enabled: false
11
11
 
12
12
  # Offense count: 2
13
- Lint/HandleExceptions:
13
+ Lint/SuppressedException:
14
14
  Enabled: false
15
15
 
16
16
  # Offense count: 5
17
17
  Metrics/AbcSize:
18
- Max: 29
18
+ Max: 30
19
19
 
20
20
  # Offense count: 1
21
21
  # Configuration parameters: CountComments.
@@ -28,7 +28,7 @@ Metrics/CyclomaticComplexity:
28
28
 
29
29
  # Offense count: 89
30
30
  # Configuration parameters: AllowURI, URISchemes.
31
- Metrics/LineLength:
31
+ Layout/LineLength:
32
32
  Max: 242
33
33
 
34
34
  # Offense count: 7
@@ -41,7 +41,7 @@ Metrics/PerceivedComplexity:
41
41
  Max: 14
42
42
 
43
43
  # Offense count: 1
44
- Style/AccessorMethodName:
44
+ Naming/AccessorMethodName:
45
45
  Enabled: false
46
46
 
47
47
  # Offense count: 18
data/.travis.yml CHANGED
@@ -4,11 +4,10 @@ before_install:
4
4
  - gem update --system
5
5
  - gem update bundler
6
6
  rvm:
7
- - 1.9.3
8
- - 2.0.0
9
- - 2.1.10
10
- - 2.2.9
11
- - 2.3.6
12
- - 2.4.3
13
- - 2.5.0
14
- - jruby-19mode
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
+ - 2.7
11
+ - 3.0
12
+ - jruby
13
+ - ruby-head
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/History.rdoc CHANGED
@@ -1,3 +1,28 @@
1
+ === 4.6.0 / 2021-04-09
2
+
3
+ * Fix error with SortedSet on Ruby 3.0 (#98).
4
+ * Remove `#reset_io` as it didn't do anything.
5
+ * Drop support for Ruby < 2.4.
6
+
7
+ === 4.5.2 / 2020-03-12
8
+
9
+ * Fix bug handling global options provided in option=value form (#47). (@orien)
10
+ * Fix ERB warnings under Ruby 2.7. (@esotericpig)
11
+ * Fix bug handling global options placed before command name (#32). (@orien)
12
+
13
+ === 4.5.1 / 2020-03-08
14
+
15
+ * Fix bug causing global options to be ignored when arguments are present (#86). (@orien)
16
+
17
+ === 4.5.0 / 2020-01-21
18
+
19
+ * Drop support for Ruby < 2.3.
20
+ * Fix bug parsing double dash (#75).
21
+
22
+ === 4.4.7 / 2018-10-22
23
+
24
+ * Update HighLine dependency to 2.0.0. (@rohitpaulk)
25
+
1
26
  === 4.4.6 / 2018-07-31
2
27
 
3
28
  * Fix unexpected internal behavior change introduced in 4.4.5.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [<img src="https://api.travis-ci.org/commander-rb/commander.svg" alt="Build Status" />](http://travis-ci.org/commander-rb/commander)
2
- [![Inline docs](http://inch-ci.org/github/commander-rb/commander.svg)](http://inch-ci.org/github/commander-rb/commander)
1
+ [<img src="https://api.travis-ci.org/commander-rb/commander.svg" alt="Build Status" />](https://travis-ci.org/commander-rb/commander)
2
+ [![Inline docs](https://inch-ci.org/github/commander-rb/commander.svg)](https://inch-ci.org/github/commander-rb/commander)
3
3
 
4
4
  # Commander
5
5
 
@@ -243,8 +243,8 @@ end
243
243
  ## Growl Notifications
244
244
 
245
245
  Commander provides methods for displaying Growl notifications. To use these
246
- methods you need to install http://github.com/tj/growl which utilizes
247
- the [growlnotify](http://growl.info/extras.php#growlnotify) executable. Note that
246
+ methods you need to install https://github.com/tj/growl which utilizes
247
+ the [growlnotify](https://growl.info/extras.php#growlnotify) executable. Note that
248
248
  growl is auto-imported by Commander when available, no need to require.
249
249
 
250
250
  ```ruby
@@ -449,7 +449,7 @@ global_option '--config FILE'
449
449
 
450
450
  ## ASCII Tables
451
451
 
452
- For feature rich ASCII tables for your terminal app check out the terminal-table gem at http://github.com/tj/terminal-table
452
+ For feature rich ASCII tables for your terminal app check out the terminal-table gem at https://github.com/tj/terminal-table
453
453
 
454
454
  +----------+-------+----+--------+-----------------------+
455
455
  | Terminal | Table | Is | Wicked | Awesome |
@@ -468,7 +468,7 @@ OR
468
468
  ## Contrib
469
469
 
470
470
  Feel free to fork and request a pull, or submit a ticket
471
- http://github.com/commander-rb/commander/issues
471
+ https://github.com/commander-rb/commander/issues
472
472
 
473
473
  ## License
474
474
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'rubocop/rake_task'
@@ -10,4 +12,4 @@ end
10
12
 
11
13
  RuboCop::RakeTask.new
12
14
 
13
- task default: [:spec, :rubocop]
15
+ task default: %i[spec rubocop]
data/bin/commander CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rubygems'
4
5
  require 'commander/import'
@@ -97,7 +98,7 @@ command :init do |c|
97
98
  File.chmod 0755, file
98
99
  say "Initialized template in #{file}"
99
100
  end
100
- rescue => e
101
+ rescue StandardError => e
101
102
  abort e
102
103
  end
103
104
  end
data/commander.gemspec CHANGED
@@ -1,6 +1,6 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
4
  require 'commander/version'
5
5
 
6
6
  Gem::Specification.new do |s|
@@ -12,21 +12,24 @@ Gem::Specification.new do |s|
12
12
  s.homepage = 'https://github.com/commander-rb/commander'
13
13
  s.summary = 'The complete solution for Ruby command-line executables'
14
14
  s.description = 'The complete solution for Ruby command-line executables. Commander bridges the gap between other terminal related libraries you know and love (OptionParser, HighLine), while providing many new features, and an elegant API.'
15
+ s.metadata = {
16
+ 'bug_tracker_uri' => "#{s.homepage}/issues",
17
+ 'changelog_uri' => "#{s.homepage}/blob/master/History.rdoc",
18
+ 'documentation_uri' => "https://www.rubydoc.info/gems/commander/#{s.version}",
19
+ 'homepage_uri' => s.homepage,
20
+ 'source_code_uri' => "#{s.homepage}/tree/v#{s.version}",
21
+ }
22
+ s.required_ruby_version = '>= 2.4'
15
23
 
16
24
  s.files = `git ls-files`.split("\n")
17
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
26
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
27
  s.require_paths = ['lib']
20
28
 
21
- s.add_runtime_dependency('highline', '~> 1.7.2')
29
+ s.add_runtime_dependency('highline', '~> 2.0.0')
22
30
 
23
- s.add_development_dependency('rspec', '~> 3.2')
24
31
  s.add_development_dependency('rake')
32
+ s.add_development_dependency('rspec', '~> 3.2')
33
+ s.add_development_dependency('rubocop', '~> 1.12.1')
25
34
  s.add_development_dependency('simplecov')
26
- if RUBY_VERSION < '2.0'
27
- s.add_development_dependency('rubocop', '~> 0.41.1')
28
- s.add_development_dependency('json', '< 2.0')
29
- else
30
- s.add_development_dependency('rubocop', '~> 0.49.1')
31
- end
32
35
  end
data/lib/commander.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2008-2009 TJ Holowaychuk <tj@vision-media.ca>
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blank
2
4
  def self.included(base)
3
5
  base.class_eval do
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'optparse'
2
4
 
3
5
  module Commander
4
6
  class Command
5
- attr_accessor :name, :examples, :syntax, :description
6
- attr_accessor :summary, :proxy_options, :options
7
+ attr_accessor :name, :examples, :syntax, :description, :summary, :proxy_options, :options
8
+ attr_reader :global_options
7
9
 
8
10
  ##
9
11
  # Options struct.
@@ -38,6 +40,7 @@ module Commander
38
40
  def initialize(name)
39
41
  @name, @examples, @when_called = name.to_s, [], []
40
42
  @options, @proxy_options = [], []
43
+ @global_options = []
41
44
  end
42
45
 
43
46
  ##
@@ -138,6 +141,7 @@ module Commander
138
141
 
139
142
  def when_called(*args, &block)
140
143
  fail ArgumentError, 'must pass an object, class, or block.' if args.empty? && !block
144
+
141
145
  @when_called = block ? [block] : args
142
146
  end
143
147
  alias action when_called
@@ -161,6 +165,7 @@ module Commander
161
165
 
162
166
  def parse_options_and_call_procs(*args)
163
167
  return args if args.empty?
168
+
164
169
  # empty proxy_options before populating via OptionParser
165
170
  # prevents duplication of options if the command is run twice
166
171
  proxy_options.clear
@@ -180,8 +185,8 @@ module Commander
180
185
 
181
186
  case object
182
187
  when Proc then object.call(args, options)
183
- when Class then meth != :call ? object.new.send(meth, args, options) : object.new(args, options)
184
- else object.send(meth, args, options) if object
188
+ when Class then meth == :call ? object.new(args, options) : object.new.send(meth, args, options)
189
+ else object&.send(meth, args, options)
185
190
  end
186
191
  end
187
192
 
@@ -190,7 +195,7 @@ module Commander
190
195
  # collected by the #option_proc.
191
196
 
192
197
  def proxy_option_struct
193
- proxy_options.each_with_object(Options.new) do |(option, value), options|
198
+ (global_options + proxy_options).each_with_object(Options.new) do |(option, value), options|
194
199
  # options that are present will evaluate to true
195
200
  value = true if value.nil?
196
201
  options.__send__ :"#{option}=", value
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Commander
2
4
  def configure(*configuration_opts, &configuration_block)
3
5
  configuration_module = Module.new
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'commander/core_ext/array'
2
4
  require 'commander/core_ext/object'
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Array
2
4
  ##
3
5
  # Split _string_ into an array. Used in
4
- # conjunction with Highline's #ask, or #ask_for_array
6
+ # conjunction with HighLine's #ask, or #ask_for_array
5
7
  # methods, which must respond to #parse.
6
8
  #
7
9
  # This method allows escaping of whitespace. For example
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Object
2
4
  ##
3
5
  # Return the current binding.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Commander
2
4
  module Delegates
3
5
  %w(
@@ -11,7 +13,7 @@ module Commander
11
13
  always_trace!
12
14
  never_trace!
13
15
  ).each do |meth|
14
- eval <<-END, binding, __FILE__, __LINE__
16
+ eval <<-END, binding, __FILE__, __LINE__ + 1
15
17
  def #{meth}(*args, &block)
16
18
  ::Commander::Runner.instance.#{meth}(*args, &block)
17
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Commander
2
4
  module HelpFormatter
3
5
  autoload :Base, 'commander/help_formatters/base'
@@ -43,7 +45,7 @@ module Commander
43
45
  module_function
44
46
 
45
47
  def indent(amount, text)
46
- text.to_s.gsub("\n", "\n" + (' ' * amount))
48
+ text.to_s.gsub("\n", "\n#{' ' * amount}")
47
49
  end
48
50
  end
49
51
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Commander
2
4
  ##
3
5
  # = Help Formatter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'erb'
2
4
 
3
5
  module Commander
@@ -12,7 +14,11 @@ module Commander
12
14
  end
13
15
 
14
16
  def template(name)
15
- ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal', "#{name}.erb")), nil, '-')
17
+ if RUBY_VERSION < '2.6'
18
+ ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal', "#{name}.erb")), nil, '-')
19
+ else
20
+ ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal', "#{name}.erb")), trim_mode: '-')
21
+ end
16
22
  end
17
23
  end
18
24
  end
@@ -1,22 +1,22 @@
1
1
 
2
- <%= $terminal.color "NAME", :bold %>:
2
+ <%= HighLine.default_instance.color "NAME", :bold %>:
3
3
 
4
4
  <%= @name %>
5
5
  <% if @syntax -%>
6
6
 
7
- <%= $terminal.color "SYNOPSIS", :bold %>:
7
+ <%= HighLine.default_instance.color "SYNOPSIS", :bold %>:
8
8
 
9
9
  <%= @syntax -%>
10
10
 
11
11
  <% end -%>
12
12
 
13
- <%= $terminal.color "DESCRIPTION", :bold %>:
13
+ <%= HighLine.default_instance.color "DESCRIPTION", :bold %>:
14
14
 
15
15
  <%= Commander::HelpFormatter.indent 4, (@description || @summary || 'No description.') -%>
16
16
 
17
17
  <% unless @examples.empty? -%>
18
18
 
19
- <%= $terminal.color "EXAMPLES", :bold %>:
19
+ <%= HighLine.default_instance.color "EXAMPLES", :bold %>:
20
20
  <% for description, command in @examples -%>
21
21
 
22
22
  # <%= description %>
@@ -25,10 +25,10 @@
25
25
  <% end -%>
26
26
  <% unless @options.empty? -%>
27
27
 
28
- <%= $terminal.color "OPTIONS", :bold %>:
28
+ <%= HighLine.default_instance.color "OPTIONS", :bold %>:
29
29
  <% for option in @options -%>
30
30
 
31
- <%= option[:switches].join ', ' %>
31
+ <%= option[:switches].join ', ' %>
32
32
  <%= Commander::HelpFormatter.indent 8, option[:description] %>
33
33
  <% end -%>
34
34
  <% end -%>