Class: LocalVault::CLI::HelpShell

Inherits:
Thor::Shell::Color
  • Object
show all
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

Instance Method Details

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, options = {})
  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

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(message, options = {})
  indent = options[:indent] || 0
  prose  = []

  message.to_s.lines.each do |line|
    line = line.chomp
    if line.lstrip.start_with?("\x05")
      wrap_prose(prose, options)
      stdout.puts("#{" " * indent}#{decorate(line.sub("\x05", ''))}")
    elsif line.strip.empty?
      wrap_prose(prose, options)
      stdout.puts
    else
      prose << line
    end
  end

  wrap_prose(prose, options)
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(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/))
  if color.nil? && message.is_a?(String)
    message = message.lines.map { |line| decorate(line.chomp) }.join("\n")
  end
  super
end