Module: Clamp::Help

Included in:
Command
Defined in:
lib/clamp/help.rb

Overview

Command help generation.

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#declared_usage_descriptionsObject (readonly)

Returns the value of attribute declared_usage_descriptions.



17
18
19
# File 'lib/clamp/help.rb', line 17

def declared_usage_descriptions
  @declared_usage_descriptions
end

#descriptionObject

Returns the value of attribute description.



32
33
34
# File 'lib/clamp/help.rb', line 32

def description
  @description
end

Instance Method Details



28
29
30
# File 'lib/clamp/help.rb', line 28

def banner(description)
  self.description = description
end

#derived_usage_descriptionObject



34
35
36
37
38
# File 'lib/clamp/help.rb', line 34

def derived_usage_description
  parts = ["[OPTIONS]"]
  parts += parameters.map(&:name)
  parts.join(" ")
end

#help(invocation_path, builder = Builder.new) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/clamp/help.rb', line 44

def help(invocation_path, builder = Builder.new)
  help = builder
  help.add_usage(invocation_path, usage_descriptions)
  help.add_description(description)
  help.add_list(Clamp.message(:parameters_heading), parameters) if has_parameters?
  help.add_list(Clamp.message(:subcommands_heading), recognised_subcommands) if has_subcommands?
  help.add_list(Clamp.message(:options_heading), recognised_options)
  help.string
end

#usage(usage) ⇒ Object



12
13
14
15
# File 'lib/clamp/help.rb', line 12

def usage(usage)
  @declared_usage_descriptions ||= []
  @declared_usage_descriptions << usage
end

#usage_descriptionsObject



40
41
42
# File 'lib/clamp/help.rb', line 40

def usage_descriptions
  declared_usage_descriptions || [derived_usage_description]
end