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.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -6
- data/.rubocop_todo.yml +4 -4
- data/.travis.yml +7 -8
- data/Gemfile +2 -0
- data/History.rdoc +25 -0
- data/README.md +6 -6
- data/Rakefile +3 -1
- data/bin/commander +2 -1
- data/commander.gemspec +13 -10
- data/lib/commander.rb +2 -0
- data/lib/commander/blank.rb +2 -0
- data/lib/commander/command.rb +10 -5
- data/lib/commander/configure.rb +2 -0
- data/lib/commander/core_ext.rb +2 -0
- data/lib/commander/core_ext/array.rb +3 -1
- data/lib/commander/core_ext/object.rb +2 -0
- data/lib/commander/delegates.rb +3 -1
- data/lib/commander/help_formatters.rb +3 -1
- data/lib/commander/help_formatters/base.rb +2 -0
- data/lib/commander/help_formatters/terminal.rb +7 -1
- data/lib/commander/help_formatters/terminal/command_help.erb +6 -6
- data/lib/commander/help_formatters/terminal/help.erb +7 -7
- data/lib/commander/help_formatters/terminal_compact.rb +7 -1
- data/lib/commander/import.rb +2 -0
- data/lib/commander/methods.rb +4 -2
- data/lib/commander/platform.rb +2 -0
- data/lib/commander/runner.rb +44 -36
- data/lib/commander/user_interaction.rb +27 -21
- data/lib/commander/version.rb +3 -1
- data/spec/command_spec.rb +29 -0
- data/spec/configure_spec.rb +2 -0
- data/spec/core_ext/array_spec.rb +3 -1
- data/spec/core_ext/object_spec.rb +2 -0
- data/spec/help_formatters/terminal_compact_spec.rb +2 -0
- data/spec/help_formatters/terminal_spec.rb +2 -0
- data/spec/methods_spec.rb +5 -3
- data/spec/runner_spec.rb +123 -8
- data/spec/spec_helper.rb +15 -4
- data/spec/ui_spec.rb +4 -2
- metadata +34 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f91f8a37c32e7971823b150b8b89d7f992a6971c66351ae7527b27cdbf0926db
|
4
|
+
data.tar.gz: bcd3c3131f145cea800da48c7231a6d3b0b892eed9107fd64dac52b03da2f44b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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
|
-
#
|
11
|
-
|
12
|
-
|
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/
|
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/
|
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/
|
13
|
+
Lint/SuppressedException:
|
14
14
|
Enabled: false
|
15
15
|
|
16
16
|
# Offense count: 5
|
17
17
|
Metrics/AbcSize:
|
18
|
-
Max:
|
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
|
-
|
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
|
-
|
44
|
+
Naming/AccessorMethodName:
|
45
45
|
Enabled: false
|
46
46
|
|
47
47
|
# Offense count: 18
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
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" />](
|
2
|
-
[
|
2
|
+
[](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
|
247
|
-
the [growlnotify](
|
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
|
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
|
-
|
471
|
+
https://github.com/commander-rb/commander/issues
|
472
472
|
|
473
473
|
## License
|
474
474
|
|
data/Rakefile
CHANGED
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
$LOAD_PATH.push File.expand_path('
|
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', '~>
|
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
data/lib/commander/blank.rb
CHANGED
data/lib/commander/command.rb
CHANGED
@@ -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
|
-
|
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
|
184
|
-
else 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
|
data/lib/commander/configure.rb
CHANGED
data/lib/commander/core_ext.rb
CHANGED
@@ -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
|
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
|
data/lib/commander/delegates.rb
CHANGED
@@ -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
|
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
|
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
|
-
|
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
|
-
<%=
|
2
|
+
<%= HighLine.default_instance.color "NAME", :bold %>:
|
3
3
|
|
4
4
|
<%= @name %>
|
5
5
|
<% if @syntax -%>
|
6
6
|
|
7
|
-
<%=
|
7
|
+
<%= HighLine.default_instance.color "SYNOPSIS", :bold %>:
|
8
8
|
|
9
9
|
<%= @syntax -%>
|
10
10
|
|
11
11
|
<% end -%>
|
12
12
|
|
13
|
-
<%=
|
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
|
-
<%=
|
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
|
-
<%=
|
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 -%>
|