lib/cl/help/cmd.rb in cl-0.1.12 vs lib/cl/help/cmd.rb in cl-0.1.13

- old
+ new

@@ -11,11 +11,11 @@ def initialize(cmd) @cmd = cmd end def format - [usage, arguments, options, common, summary, description].compact.join("\n\n") + [usage, summary, description, arguments, options, common, examples].compact.join("\n\n") end def usage "Usage: #{Usage.new(cmd).format}" end @@ -38,10 +38,14 @@ def common ['Common Options:', table(:cmmn)] if common? end + def examples + ['Examples:', indent(cmd.examples)] if cmd.examples + end + def table(name) table = send(name) indent(table.to_s(width - table.width + 5)) end @@ -75,11 +79,11 @@ def requireds return unless cmd.required? opts = cmd.required strs = opts.map { |alts| alts.map { |alt| Array(alt).join(' and ') }.join(', or ' ) } strs = strs.map { |str| "Either #{str} are required." }.join("\n") - indent(strs) + indent(strs) unless strs.empty? end def common? cmd.superclass < Cl::Cmd end @@ -88,11 +92,11 @@ [args.width, opts.width, cmmn.width].max end def format_obj(obj) opts = [] - opts << "type: #{format_type(obj)}" + opts << "type: #{format_type(obj)}" unless obj.type == :flag opts << 'required: true' if obj.required? opts += format_opt(obj) if obj.is_a?(Opt) opts = opts.join(', ') opts = "(#{opts})" if obj.description && !opts.empty? opts = [obj.description, opts] @@ -105,9 +109,10 @@ opts << "requires: #{opt.requires.join(', ')}" if opt.requires? opts << "default: #{format_default(opt)}" if opt.default? opts << "known values: #{format_enum(opt)}" if opt.enum? opts << "format: #{opt.format}" if opt.format? opts << "downcase: true" if opt.downcase? + opts << "min: #{opt.min}" if opt.min? opts << "max: #{opt.max}" if opt.max? opts << "e.g.: #{opt.example}" if opt.example? opts << "see: #{opt.see}" if opt.see? opts << format_deprecated(opt) if opt.deprecated? opts.compact