class Cl::Help::Cmd
Public Instance Methods
args()
click to toggle source
# File lib/cl/help/cmd.rb, line 47 def args @args ||= begin Table.new(cmd.args.map { |arg| [arg.name, format_obj(arg)] }) end end
arguments()
click to toggle source
# File lib/cl/help/cmd.rb, line 26 def arguments ['Arguments:', table(:args)] if args.any? end
cmmn()
click to toggle source
# File lib/cl/help/cmd.rb, line 64 def cmmn @cmmn ||= begin opts = cmd.superclass.opts opts = opts.reject(&:internal?) strs = Table.new(rjust(opts.map(&:strs))) opts = opts.map { |opt| format_obj(opt) } Table.new(strs.rows.zip(opts)) end end
common()
click to toggle source
# File lib/cl/help/cmd.rb, line 34 def common ['Common Options:', table(:cmmn)] if common? end
common?()
click to toggle source
# File lib/cl/help/cmd.rb, line 99 def common? cmd.superclass < Cl::Cmd end
description()
click to toggle source
# File lib/cl/help/cmd.rb, line 22 def description ['Description:', indent(cmd.description)] if cmd.description end
examples()
click to toggle source
# File lib/cl/help/cmd.rb, line 38 def examples ['Examples:', indent(cmd.examples)] if cmd.examples end
format()
click to toggle source
# File lib/cl/help/cmd.rb, line 10 def format [usage, summary, description, arguments, options, common, examples].compact.join("\n\n") end
indent(str)
click to toggle source
# File lib/cl/help/cmd.rb, line 113 def indent(str) str.lines.map { |line| " #{line}".rstrip }.join("\n") end
negate(opt)
click to toggle source
# File lib/cl/help/cmd.rb, line 86 def negate(opt) negations = opt.negate.map { |str| "#{str}-" }.join('|') opt.long.dup.insert(2, "[#{negations}]") end
negate?(opt)
click to toggle source
# File lib/cl/help/cmd.rb, line 81 def negate?(opt) negations = opt.negate.map { |str| "#{str}-" }.join('|') opt.long && opt.negate? && opt.long !~ /\[#{negations}\]/ end
opt_strs(opt)
click to toggle source
# File lib/cl/help/cmd.rb, line 74 def opt_strs(opt) return opt.strs if !opt.flag? || opt.help? opts = [opt.short] opts.push(negate?(opt) ? negate(opt) : opt.long) opts.compact end
options()
click to toggle source
# File lib/cl/help/cmd.rb, line 30 def options ['Options:', requireds, table(:opts)].compact if opts.any? end
opts()
click to toggle source
# File lib/cl/help/cmd.rb, line 53 def opts @opts ||= begin opts = cmd.opts.to_a opts = opts.reject(&:internal?) opts = opts - cmd.superclass.opts.to_a if common? strs = Table.new(rjust(opts.map { |opt| opt_strs(opt) })) opts = opts.map { |opt| format_obj(opt) } Table.new(strs.rows.zip(opts)) end end
requireds()
click to toggle source
# File lib/cl/help/cmd.rb, line 91 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) unless strs.empty? end
rjust(objs)
click to toggle source
# File lib/cl/help/cmd.rb, line 107 def rjust(objs) return objs unless objs.any? width = objs.max_by(&:size).size objs.map { |objs| [*Array.new(width - objs.size) { '' }, *objs] } end
summary()
click to toggle source
# File lib/cl/help/cmd.rb, line 18 def summary ['Summary:', indent(cmd.summary)] if cmd.summary end
table(name)
click to toggle source
# File lib/cl/help/cmd.rb, line 42 def table(name) table = send(name) indent(table.to_s(width - table.width + 5)) end
usage()
click to toggle source
# File lib/cl/help/cmd.rb, line 14 def usage "Usage: #{Usage.new(ctx, cmd).format.join("\n or: ")}" end
width()
click to toggle source
# File lib/cl/help/cmd.rb, line 103 def width [args.width, opts.width, cmmn.width].max end