Class: Tomo::CLI::Usage

Inherits:
Object
  • Object
show all
Defined in:
lib/tomo/cli/usage.rb

Instance Method Summary collapse

Constructor Details

#initializeUsage

Returns a new instance of Usage.



6
7
8
9
# File 'lib/tomo/cli/usage.rb', line 6

def initialize
  @options = []
  @banner_proc = proc { "" }
end

Instance Method Details

#add_option(spec, desc) ⇒ Object



11
12
13
14
15
16
# File 'lib/tomo/cli/usage.rb', line 11

def add_option(spec, desc)
  options << [
    spec.start_with?("--") ? "    #{spec}" : spec,
    desc
  ]
end

#banner=(banner) ⇒ Object



18
19
20
# File 'lib/tomo/cli/usage.rb', line 18

def banner=(banner)
  @banner_proc = banner.respond_to?(:call) ? banner : proc { banner }
end

#to_sObject



22
23
24
# File 'lib/tomo/cli/usage.rb', line 22

def to_s
  indent(["", banner_proc.call, "Options:", "", indent(options_help), "\n"].join("\n"))
end