Module: Posto::Help
- Defined in:
- lib/posto/help.rb
Class Method Summary collapse
- .format(hash) ⇒ Object
- .format_alias(command_alias, alias_for) ⇒ Object
- .format_command(command_alias) ⇒ Object
- .format_command_definition(command, definition) ⇒ Object
- .format_commands(commands) ⇒ Object
- .format_list(commands, title) ⇒ Object
- .help_text ⇒ Object
- .parse(md_file) ⇒ Object
- .read ⇒ Object
Class Method Details
.format(hash) ⇒ Object
22 23 24 25 |
# 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) ⇒ Object
45 46 47 |
# 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) ⇒ Object
49 50 51 |
# File 'lib/posto/help.rb', line 49 def format_command(command_alias) ' ' * 3 + command_alias.ljust(18) end |
.format_command_definition(command, definition) ⇒ Object
37 38 39 40 41 42 43 |
# 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) ⇒ Object
31 32 33 34 35 |
# 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) ⇒ Object
27 28 29 |
# File 'lib/posto/help.rb', line 27 def format_list(commands, title) "\n#{title}:\n#{format_commands(commands)}" end |
.help_text ⇒ Object
4 5 6 |
# File 'lib/posto/help.rb', line 4 def help_text format(parse(read)) end |
.parse(md_file) ⇒ Object
13 14 15 16 17 18 19 20 |
# 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 ⇒ Object
8 9 10 11 |
# 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 |