Module: Clamp::Help
- Included in:
- Command
- Defined in:
- lib/wpb/clamp/help.rb
Instance Attribute Summary collapse
-
#declared_usage_descriptions ⇒ Object
readonly
Returns the value of attribute declared_usage_descriptions.
-
#description ⇒ Object
Returns the value of attribute description.
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.
12 13 14 |
# File 'lib/wpb/clamp/help.rb', line 12 def declared_usage_descriptions @declared_usage_descriptions end |
#description ⇒ Object
Returns the value of attribute description.
23 24 25 |
# File 'lib/wpb/clamp/help.rb', line 23 def description @description end |
Instance Method Details
#derived_usage_description ⇒ Object
25 26 27 28 29 |
# File 'lib/wpb/clamp/help.rb', line 25 def derived_usage_description parts = parameters.map { |a| a.name } parts.unshift("[OPTIONS]") if parts.join(" ") end |
#help(invocation_path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wpb/clamp/help.rb', line 35 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 if description help.puts "" help.puts description.gsub(/^/, " ") 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
7 8 9 10 |
# File 'lib/wpb/clamp/help.rb', line 7 def usage(usage) @declared_usage_descriptions ||= [] @declared_usage_descriptions << usage end |
#usage_descriptions ⇒ Object
31 32 33 |
# File 'lib/wpb/clamp/help.rb', line 31 def usage_descriptions declared_usage_descriptions || [derived_usage_description] end |