module Posto::Help
Public Class Methods
format(hash)
click to toggle source
# File lib/posto/help.rb, line 22 def format(hash) hash.delete(:title) hash.map { |title, commands| format_list(commands, title) }.join("\n") end
format_alias(command_alias, alias_for)
click to toggle source
# File lib/posto/help.rb, line 45 def format_alias(command_alias, alias_for) "#{format_command command_alias}alias for '#{alias_for}'" end
format_command(command_alias)
click to toggle source
# File lib/posto/help.rb, line 49 def format_command(command_alias) ' ' * 3 + command_alias.ljust(18) end
format_command_definition(command, definition)
click to toggle source
# File lib/posto/help.rb, line 37 def format_command_definition(command, definition) aliases = command.split(', ') command = aliases.first aliases = aliases[1..-1] (["#{format_command command}#{definition}"] + aliases.map { |command_alias| format_alias(command_alias, command) }).join("\n") end
format_commands(commands)
click to toggle source
# File lib/posto/help.rb, line 31 def format_commands(commands) commands.map do |command, definition| format_command_definition(command, definition) end.join("\n") end
format_list(commands, title)
click to toggle source
# File lib/posto/help.rb, line 27 def format_list(commands, title) "\n#{title}:\n#{format_commands(commands)}" end
help_text()
click to toggle source
# File lib/posto/help.rb, line 4 def help_text format(parse(read)) end
parse(md_file)
click to toggle source
# File lib/posto/help.rb, line 13 def parse(md_file) md_file.map { |x| x.split(": ") }.inject({}) do |memo, o| memo[:title] = o.first if o.size == 1 memo[memo[:title]] ||= {} memo[memo[:title]][o.first]= o.last if o.size == 2 memo end end
read()
click to toggle source
# File lib/posto/help.rb, line 8 def read lines = ::File.read("#{::File.dirname(__FILE__)}/help.md").lines lines.map { |line| line.chomp }.reject(&:empty?).map { |line| line.gsub /(### |`)/, "" } end