class Fuelcell::Help::Builder
Public Instance Methods
build_commands(cmd, path, data = {})
click to toggle source
# File lib/fuelcell/help/builder.rb, line 48 def build_commands(cmd, path, data = {}) data[:commands] = [] cmd.each do |_, command| data[:commands] << { name: command.name, path: path, desc: command.desc || '' } end data end
build_desc(cmd, data = {})
click to toggle source
# File lib/fuelcell/help/builder.rb, line 60 def build_desc(cmd, data = {}) data[:desc] = cmd.desc data end
build_options(opt_manager, data = {})
click to toggle source
# File lib/fuelcell/help/builder.rb, line 37 def build_options(opt_manager, data = {}) options = [] opt_manager.each do |opt| next if opt.required? options << common_opt_data(opt).merge!(banner: opt.banner) end data[:options] = options data end
build_usage(script_name, path, cmd, data = {})
click to toggle source
@param script_name [String] name of script you asked help from @param path [String] path of command you need help for @param cmd [Fuelcell::Action::Command] command you need help with @param data [Hash] stores the structure of the help content @return [Hash]
# File lib/fuelcell/help/builder.rb, line 21 def build_usage(script_name, path, cmd, data = {}) usage = {} usage[:label] = 'Usage:' usage[:path] = "#{script_name} #{path}".strip usage[:text] = cmd.usage.nil? ? '' : cmd.usage usage[:args] = [] usage[:opts] = [] cmd.opts.required_opts.each do |(_, opt)| usage[:opts] << common_opt_data(opt) end data[:usage] = usage data end
call(root, args, help = {})
click to toggle source
# File lib/fuelcell/help/builder.rb, line 5 def call(root, args, help = {}) args = args.is_a?(Array) ? args : args.raw cmd = args.empty? ? root : root.locate(args) path = args.join(' ').strip build_usage(root.name, path, cmd, help) build_options(cmd.opts, help) build_commands(cmd, path, help) build_desc(cmd, help) help end
Protected Instance Methods
common_opt_data(opt)
click to toggle source
# File lib/fuelcell/help/builder.rb, line 67 def common_opt_data(opt) { short: opt.short, long: opt.long, type: opt.type } end