Module: Ace::Support::Cli::Help::Concise

Defined in:
lib/ace/support/cli/help/concise.rb

Class Method Summary collapse

Class Method Details

.call(command, name) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/ace/support/cli/help/concise.rb', line 8

def self.call(command, name)
  [
    header_line(command, name),
    usage_line(command, name),
    options_block(command),
    examples_block(command, name),
    footer_line(name)
  ].compact.join("\n\n")
end

.examples_block(command, name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/ace/support/cli/help/concise.rb', line 35

def self.examples_block(command, name)
  items = Banner.examples(command)
  return nil if items.empty?

  rendered = items.first(3).map do |item|
    cleaned = item.to_s.sub(/\A#{Regexp.escape(name)}\s*/, "")
    "  $ #{name} #{cleaned}".rstrip
  end
  "Examples:\n#{rendered.join("\n")}"
end

.first_line(text) ⇒ Object



57
58
59
60
61
# File 'lib/ace/support/cli/help/concise.rb', line 57

def self.first_line(text)
  return nil if text.nil?

  text.to_s.strip.split("\n").first&.strip
end


46
47
48
# File 'lib/ace/support/cli/help/concise.rb', line 46

def self.footer_line(name)
  "Run '#{name} --help' for full details."
end

.format_option(option) ⇒ Object



50
51
52
53
54
55
# File 'lib/ace/support/cli/help/concise.rb', line 50

def self.format_option(option)
  name = Banner.option_name(option).sub("=VALUE1,VALUE2,..", " VALUES").sub("=VALUE", " VALUE")
  aliases = Banner.option_aliases(option)
  name = "#{name}, #{aliases.join(", ")}" if aliases.any?
  "  --#{name}"
end

.header_line(command, name) ⇒ Object



18
19
20
21
# File 'lib/ace/support/cli/help/concise.rb', line 18

def self.header_line(command, name)
  summary = first_line(command.respond_to?(:description) ? command.description : nil)
  summary ? "#{name} - #{summary}" : name.to_s
end

.options_block(command) ⇒ Object



29
30
31
32
33
# File 'lib/ace/support/cli/help/concise.rb', line 29

def self.options_block(command)
  lines = Banner.options(command).map { |option| format_option(option) }
  lines << "  --help, -h            Show this help"
  "Options:\n#{lines.join("\n")}"
end

.usage_line(command, name) ⇒ Object



23
24
25
26
27
# File 'lib/ace/support/cli/help/concise.rb', line 23

def self.usage_line(command, name)
  args = Banner.arguments_synopsis(command)
  opts = Banner.options(command).any? ? " [OPTIONS]" : ""
  "Usage: #{name}#{args}#{opts}"
end