Sha256: 57903a869877eb0941ff29195ba99d48b7ba5adfce4d0507fcb81f434b7e4568
Contents?: true
Size: 1.18 KB
Versions: 18
Compression:
Stored size: 1.18 KB
Contents
module Commander module HelpFormatter autoload :Base, 'commander/help_formatters/base' autoload :Terminal, 'commander/help_formatters/terminal' autoload :TerminalCompact, 'commander/help_formatters/terminal_compact' class Context def initialize(target) @target = target end def get_binding @target.instance_eval { binding }.tap do |bind| decorate_binding(bind) end end # No-op, override in subclasses. def decorate_binding(_bind) end end class ProgramContext < Context def decorate_binding(bind) bind.eval("max_command_length = #{max_command_length(bind)}") bind.eval("max_aliases_length = #{max_aliases_length(bind)}") end def max_command_length(bind) max_key_length(bind.eval('@commands')) end def max_aliases_length(bind) max_key_length(bind.eval('@aliases')) end def max_key_length(hash, default = 20) longest = hash.keys.max_by(&:size) longest ? longest.size : default end end module_function def indent(amount, text) text.to_s.gsub("\n", "\n" + (' ' * amount)) end end end
Version data entries
18 entries across 18 versions & 3 rubygems