Class: Commander::HelpFormatter::ProgramContext
- Defined in:
- lib/commander/help_formatters.rb
Overview
A Context for rendering the global help template (see HelpFormatter::Terminal#render), decorating the target Runner's binding with +max_command_length+/+max_aliases_length+ locals so the template can align its columns.
Instance Method Summary collapse
- #decorate_binding(bind) ⇒ Object
-
#max_aliases_length(bind) ⇒ Object
Length, in characters, of the longest registered command alias.
-
#max_command_length(bind) ⇒ Object
Length, in characters, of the longest registered command name.
-
#max_key_length(hash, default = 20) ⇒ Object
Length of the longest key in hash, or default when hash is empty.
Methods inherited from Context
Constructor Details
This class inherits a constructor from Commander::HelpFormatter::Context
Instance Method Details
#decorate_binding(bind) ⇒ Object
45 46 47 48 |
# File 'lib/commander/help_formatters.rb', line 45 def decorate_binding(bind) bind.eval("max_command_length = #{max_command_length(bind)}") bind.eval("max_aliases_length = #{max_aliases_length(bind)}") end |
#max_aliases_length(bind) ⇒ Object
Length, in characters, of the longest registered command alias.
58 59 60 |
# File 'lib/commander/help_formatters.rb', line 58 def max_aliases_length(bind) max_key_length(bind.eval('@aliases')) end |
#max_command_length(bind) ⇒ Object
Length, in characters, of the longest registered command name.
52 53 54 |
# File 'lib/commander/help_formatters.rb', line 52 def max_command_length(bind) max_key_length(bind.eval('@commands')) end |
#max_key_length(hash, default = 20) ⇒ Object
Length of the longest key in hash, or default when hash is empty.
64 65 66 67 |
# File 'lib/commander/help_formatters.rb', line 64 def max_key_length(hash, default = 20) longest = hash.keys.max_by(&:size) longest ? longest.size : default end |