Class: Slk::Support::HelpFormatter
- Inherits:
-
Object
- Object
- Slk::Support::HelpFormatter
- Defined in:
- lib/slk/support/help_formatter.rb
Overview
Formats help text with auto-aligned columns
Example usage:
help = HelpFormatter.new("slk status [text] [emoji] [options]")
help.description("Get or set your Slack status.")
help.note("GET shows all workspaces by default. SET applies to primary only.")
help.section("EXAMPLES") do |s|
s.example("slk status", "Show status (all workspaces)")
s.example("slk status clear", "Clear status")
end
help.section("OPTIONS") do |s|
s.option("-n, --limit N", "Messages per channel (default: 10)")
s.option("--muted", "Include muted channels")
end
puts help.render
Defined Under Namespace
Classes: Section
Instance Method Summary collapse
- #description(text) ⇒ Object
-
#initialize(usage) ⇒ HelpFormatter
constructor
A new instance of HelpFormatter.
- #note(text) ⇒ Object
- #render ⇒ Object
- #section(title, &block) ⇒ Object
Constructor Details
#initialize(usage) ⇒ HelpFormatter
Returns a new instance of HelpFormatter.
25 26 27 28 29 30 |
# File 'lib/slk/support/help_formatter.rb', line 25 def initialize(usage) @usage = usage @description = nil @notes = [] @sections = [] end |
Instance Method Details
#description(text) ⇒ Object
32 33 34 35 |
# File 'lib/slk/support/help_formatter.rb', line 32 def description(text) @description = text self end |
#note(text) ⇒ Object
37 38 39 40 |
# File 'lib/slk/support/help_formatter.rb', line 37 def note(text) @notes << text self end |
#render ⇒ Object
49 50 51 52 53 54 |
# File 'lib/slk/support/help_formatter.rb', line 49 def render lines = build_header lines.concat(build_sections) lines.pop if lines.last == '' lines.join("\n") end |