Class: Commander::HelpFormatter::ProgramContext

Inherits:
Context show all
Defined in:
lib/commander/help_formatters.rb

Instance Method Summary collapse

Methods inherited from Context

#get_binding, #initialize

Methods included from Patches::HelpFormatterBinding

#get_binding

Constructor Details

This class inherits a constructor from Commander::HelpFormatter::Context

Instance Method Details

#decorate_binding(bind) ⇒ Object



27
28
29
30
# File 'lib/commander/help_formatters.rb', line 27

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



36
37
38
# File 'lib/commander/help_formatters.rb', line 36

def max_aliases_length(bind)
  max_key_length(bind.eval('@aliases'))
end

#max_command_length(bind) ⇒ Object



32
33
34
# File 'lib/commander/help_formatters.rb', line 32

def max_command_length(bind)
  max_key_length(bind.eval('@commands'))
end

#max_key_length(hash, default = 20) ⇒ Object



40
41
42
43
# File 'lib/commander/help_formatters.rb', line 40

def max_key_length(hash, default = 20)
  longest = hash.keys.max_by(&:size)
  longest ? longest.size : default
end