Module: Clamp::Help
- Included in:
- Command
- Defined in:
- lib/clamp/help.rb
Instance Attribute Summary collapse
-
#declared_usage_descriptions ⇒ Object
readonly
Returns the value of attribute declared_usage_descriptions.
Instance Method Summary collapse
- #derived_usage_description ⇒ Object
- #help(invocation_path) ⇒ Object
- #usage(usage) ⇒ Object
- #usage_descriptions ⇒ Object
Instance Attribute Details
#declared_usage_descriptions ⇒ Object (readonly)
Returns the value of attribute declared_usage_descriptions.
10 11 12 |
# File 'lib/clamp/help.rb', line 10 def declared_usage_descriptions @declared_usage_descriptions end |
Instance Method Details
#derived_usage_description ⇒ Object
12 13 14 15 16 17 |
# File 'lib/clamp/help.rb', line 12 def derived_usage_description parts = parameters.map { |a| a.name } parts.unshift("SUBCOMMAND") if has_subcommands? parts.unshift("[OPTIONS]") if parts.join(" ") end |
#help(invocation_path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/clamp/help.rb', line 23 def help(invocation_path) help = StringIO.new help.puts "Usage:" usage_descriptions.each_with_index do |usage, i| help.puts " #{invocation_path} #{usage}".rstrip end detail_format = " %-29s %s" if has_parameters? help.puts "\nParameters:" parameters.each do |parameter| help.puts detail_format % parameter.help end end if has_subcommands? help.puts "\nSubcommands:" recognised_subcommands.each do |subcommand| help.puts detail_format % subcommand.help end end if help.puts "\nOptions:" .each do |option| help.puts detail_format % option.help end end help.string end |
#usage(usage) ⇒ Object
5 6 7 8 |
# File 'lib/clamp/help.rb', line 5 def usage(usage) @declared_usage_descriptions ||= [] @declared_usage_descriptions << usage end |
#usage_descriptions ⇒ Object
19 20 21 |
# File 'lib/clamp/help.rb', line 19 def usage_descriptions declared_usage_descriptions || [derived_usage_description] end |