Sha256: aa70a37fa63533c8a7545cd9e684d77d60d91aeff96549fa23e7381451092e3e
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
module Clamp module Help def usage(usage) @declared_usage_descriptions ||= [] @declared_usage_descriptions << usage end attr_reader :declared_usage_descriptions def derived_usage_description parts = parameters.map { |a| a.name } parts.unshift("SUBCOMMAND") if has_subcommands? parts.unshift("[OPTIONS]") if has_options? parts.join(" ") end def usage_descriptions declared_usage_descriptions || [derived_usage_description] end def help(command_name) help = StringIO.new help.puts "Usage:" usage_descriptions.each_with_index do |usage, i| help.puts " #{command_name} #{usage}".rstrip end detail_format = " %-29s %s" unless parameters.empty? help.puts "\nParameters:" parameters.each do |parameter| help.puts detail_format % parameter.help end end unless recognised_subcommands.empty? help.puts "\nSubcommands:" recognised_subcommands.each do |subcommand| help.puts detail_format % subcommand.help end end if has_options? help.puts "\nOptions:" recognised_options.each do |option| help.puts detail_format % option.help end end help.string end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
clamp-0.0.9 | lib/clamp/help.rb |