Module: Clamp::Help

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

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.



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

def declared_usage_descriptions
  @declared_usage_descriptions
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

Instance Method Details



23
24
25
# File 'lib/clamp/help.rb', line 23

def banner(description)
  self.description = description
end

#derived_usage_descriptionObject



29
30
31
32
33
# File 'lib/clamp/help.rb', line 29

def derived_usage_description
  parts = ["[OPTIONS]"]
  parts += parameters.map { |a| a.name }
  parts.join(" ")
end

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



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/clamp/help.rb', line 39

def help(invocation_path, builder = Builder.new)
  help = builder
  help.add_usage(invocation_path, usage_descriptions)
  help.add_description(description)
  if has_parameters?
    help.add_list("Parameters", parameters)
  end
  if has_subcommands?
    help.add_list("Subcommands", recognised_subcommands)
  end
  help.add_list("Options", recognised_options)
  help.string
end

#usage(usage) ⇒ Object



7
8
9
10
# File 'lib/clamp/help.rb', line 7

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

#usage_descriptionsObject



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

def usage_descriptions
  declared_usage_descriptions || [derived_usage_description]
end