Class: LocalVault::CLI::HelpShell
- Inherits:
-
Thor::Shell::Color
- Object
- Thor::Shell::Color
- LocalVault::CLI::HelpShell
- Defined in:
- lib/localvault/cli/help_shell.rb
Overview
Colors every help surface — the main screen, help COMMAND, and
subcommand namespaces — by hooking the shell Thor already routes all
help output through, rather than colorizing at each call site.
Thor disables color itself when stdout is not a TTY, so piped output stays plain.
Constant Summary collapse
- LABEL =
"Usage:", "Options:", "Description:", "Runtime options:"
/\A([A-Z][A-Za-z ]*:)\s*\z/- HEADING =
A leading run of caps: "GETTING STARTED", "NESTED KEY (dot-notation)"
/\A(\s*)([A-Z][A-Z0-9'\/\-]*(?: [A-Z0-9'\/\-]+)*)(?=\z|[\s(:])/
Instance Method Summary collapse
-
#print_table(array, options = {}) ⇒ Object
Option tables: green the flag column ("-v, [--vault=VAULT]").
-
#print_wrapped(message, options = {}) ⇒ Object
Thor word-wraps long descriptions, which collapses the alignment of example blocks (
localvault set K V # commentloses its spacing). - #say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/)) ⇒ Object
Instance Method Details
#print_table(array, options = {}) ⇒ Object
Option tables: green the flag column ("-v, [--vault=VAULT]").
50 51 52 53 54 55 56 |
# File 'lib/localvault/cli/help_shell.rb', line 50 def print_table(array, = {}) array = array.map do |row| first, *rest = row first.is_a?(String) && first.strip.start_with?("-") ? [set_color(first, :green), *rest] : row end super end |
#print_wrapped(message, options = {}) ⇒ Object
Thor word-wraps long descriptions, which collapses the alignment of
example blocks (localvault set K V # comment loses its spacing).
Lines flagged with \x05 — Thor's no-wrap marker, which every example in
our long_desc blocks already carries — are printed verbatim instead, so
examples stay aligned while prose still wraps to the terminal.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/localvault/cli/help_shell.rb', line 29 def print_wrapped(, = {}) indent = [:indent] || 0 prose = [] .to_s.lines.each do |line| line = line.chomp if line.lstrip.start_with?("\x05") wrap_prose(prose, ) stdout.puts("#{" " * indent}#{decorate(line.sub("\x05", ''))}") elsif line.strip.empty? wrap_prose(prose, ) stdout.puts else prose << line end end wrap_prose(prose, ) end |
#say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/)) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/localvault/cli/help_shell.rb', line 17 def say( = "", color = nil, force_new_line = (.to_s !~ /( |\t)\Z/)) if color.nil? && .is_a?(String) = .lines.map { |line| decorate(line.chomp) }.join("\n") end super end |