commander 4.3.3 → 4.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 539292421c6c437b5a79388d3736875b95a2d953
4
- data.tar.gz: dfd174077251e2415e83a49ce5a9d518457986d4
3
+ metadata.gz: 72ee1a4d6498d366df2896b19afd77d57a2fe2e5
4
+ data.tar.gz: 0c3c85152bcd33462c1f2e399c05badd4bb62b63
5
5
  SHA512:
6
- metadata.gz: 45fdd002a404d22e1c69e7c448c1e0559cbb572b051179ca9a2dbbc1b851d2e96983cb44ec92d53a32dc7dfed3cbfa782ebc4dd2c9cdee82df00f52dc4b65c81
7
- data.tar.gz: ded7f701bdadcdd2ddd2e26068121bbdc9a50c29a54908ae18d70a89f189142e286235c74be22458542e7435a7279a12489c2097668495ff15bde139b7e8338d
6
+ metadata.gz: 4c3d14e701cfe6e057f0f002aad28ffbf1d1b91ad2fa4f7a320326e161c079d5001c670b938a55090fc76a510a94e1f48b1a7474e760588d5ed8fee5223a9a41
7
+ data.tar.gz: 1ee04c92a9502fc7c0f970a52705746fc657fd9833b694b67246ce036356ac3cd9698a938b535c392c11e2939a5e177a3a99196b18d194ed6f0a0d715a599ee7
@@ -1,6 +1,11 @@
1
+ === 4.3.4 / 2015-05-03
2
+
3
+ * Fixed a regression with the compact help formatter.
4
+
1
5
  === 4.3.3 / 2015-04-21
2
6
 
3
7
  * Updated to highline 1.7.2 to fix a regression with terminal size (https://github.com/JEG2/highline/pull/139).
8
+ * Help formatting updated to look better for commands with long names. (@jszwedko)
4
9
 
5
10
  === 4.3.2 / 2015-03-31
6
11
 
@@ -4,6 +4,42 @@ module Commander
4
4
  autoload :Terminal, 'commander/help_formatters/terminal'
5
5
  autoload :TerminalCompact, 'commander/help_formatters/terminal_compact'
6
6
 
7
+ class Context
8
+ def initialize(target)
9
+ @target = target
10
+ end
11
+
12
+ def get_binding
13
+ @target.instance_eval { binding }.tap do |bind|
14
+ decorate_binding(bind)
15
+ end
16
+ end
17
+
18
+ # No-op, override in subclasses.
19
+ def decorate_binding(_bind)
20
+ end
21
+ end
22
+
23
+ class ProgramContext < Context
24
+ def decorate_binding(bind)
25
+ bind.eval("max_command_length = #{max_command_length(bind)}")
26
+ bind.eval("max_aliases_length = #{max_aliases_length(bind)}")
27
+ end
28
+
29
+ def max_command_length(bind)
30
+ max_key_length(bind.eval('@commands'))
31
+ end
32
+
33
+ def max_aliases_length(bind)
34
+ max_key_length(bind.eval('@aliases'))
35
+ end
36
+
37
+ def max_key_length(hash, default = 20)
38
+ longest = hash.keys.max_by(&:size)
39
+ longest ? longest.size : default
40
+ end
41
+ end
42
+
7
43
  module_function
8
44
 
9
45
  def indent(amount, text)
@@ -4,11 +4,11 @@ module Commander
4
4
  module HelpFormatter
5
5
  class Terminal < Base
6
6
  def render
7
- template(:help).result @runner.get_binding
7
+ template(:help).result(ProgramContext.new(@runner).get_binding)
8
8
  end
9
9
 
10
10
  def render_command(command)
11
- template(:command_help).result command.get_binding
11
+ template(:command_help).result(Context.new(command).get_binding)
12
12
  end
13
13
 
14
14
  def template(name)
@@ -1,10 +1,3 @@
1
- <%
2
- # TODO: move into formatter?
3
- longest_command = @commands.keys.max_by(&:size)
4
- max_command_length = longest_command ? longest_command.size : 20
5
- longest_alias = @aliases.keys.max_by(&:size)
6
- max_aliases_length = longest_alias ? longest_alias.size : 20
7
- %>
8
1
  <%= $terminal.color "NAME", :bold %>:
9
2
 
10
3
  <%= program :name %>
@@ -1,5 +1,3 @@
1
- <% max_command_length = @commands.keys.max_by(&:size).size %>
2
- <% max_aliases_length = @aliases.keys.max_by(&:size).size %>
3
1
  <%= program :name %>
4
2
 
5
3
  <%= program :description %>
@@ -1,3 +1,3 @@
1
1
  module Commander
2
- VERSION = '4.3.3'
2
+ VERSION = '4.3.4'
3
3
  end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Commander::HelpFormatter::TerminalCompact do
4
+ include Commander::Methods
5
+
6
+ before :each do
7
+ mock_terminal
8
+ end
9
+
10
+ describe 'global help' do
11
+ before :each do
12
+ new_command_runner 'help' do
13
+ program :help_formatter, :compact
14
+ command :'install gem' do |c|
15
+ c.syntax = 'foo install gem [options]'
16
+ c.summary = 'Install some gem'
17
+ end
18
+ end.run!
19
+ @global_help = @output.string
20
+ end
21
+
22
+ describe 'should display' do
23
+ it 'the command name' do
24
+ expect(@global_help).to include('install gem')
25
+ end
26
+
27
+ it 'the summary' do
28
+ expect(@global_help).to include('Install some gem')
29
+ end
30
+ end
31
+ end
32
+
33
+ describe 'command help' do
34
+ before :each do
35
+ new_command_runner 'help', 'install', 'gem' do
36
+ program :help_formatter, :compact
37
+ command :'install gem' do |c|
38
+ c.syntax = 'foo install gem [options]'
39
+ c.summary = 'Install some gem'
40
+ c.description = 'Install some gem, blah blah blah'
41
+ c.example 'one', 'two'
42
+ c.example 'three', 'four'
43
+ end
44
+ end.run!
45
+ @command_help = @output.string
46
+ end
47
+
48
+ describe 'should display' do
49
+ it 'the command name' do
50
+ expect(@command_help).to include('install gem')
51
+ end
52
+
53
+ it 'the description' do
54
+ expect(@command_help).to include('Install some gem, blah blah blah')
55
+ end
56
+
57
+ it 'all examples' do
58
+ expect(@command_help).to include('# one')
59
+ expect(@command_help).to include('two')
60
+ expect(@command_help).to include('# three')
61
+ expect(@command_help).to include('four')
62
+ end
63
+
64
+ it 'the syntax' do
65
+ expect(@command_help).to include('foo install gem [options]')
66
+ end
67
+ end
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commander
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.3
4
+ version: 4.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-21 00:00:00.000000000 Z
12
+ date: 2015-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
@@ -131,6 +131,7 @@ files:
131
131
  - spec/configure_spec.rb
132
132
  - spec/core_ext/array_spec.rb
133
133
  - spec/core_ext/object_spec.rb
134
+ - spec/help_formatters/terminal_compact_spec.rb
134
135
  - spec/help_formatters/terminal_spec.rb
135
136
  - spec/methods_spec.rb
136
137
  - spec/runner_spec.rb
@@ -165,6 +166,7 @@ test_files:
165
166
  - spec/configure_spec.rb
166
167
  - spec/core_ext/array_spec.rb
167
168
  - spec/core_ext/object_spec.rb
169
+ - spec/help_formatters/terminal_compact_spec.rb
168
170
  - spec/help_formatters/terminal_spec.rb
169
171
  - spec/methods_spec.rb
170
172
  - spec/runner_spec.rb