Class: Fuelcell::Help::Builder
- Inherits:
-
Object
- Object
- Fuelcell::Help::Builder
- Defined in:
- lib/fuelcell/help/builder.rb
Instance Method Summary collapse
- #build_commands(cmd, path, data = {}) ⇒ Object
- #build_desc(cmd, data = {}) ⇒ Object
- #build_options(opt_manager, data = {}) ⇒ Object
- #build_usage(script_name, path, cmd, data = {}) ⇒ Hash
- #call(root, args, help = {}) ⇒ Object
Instance Method Details
#build_commands(cmd, path, data = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# 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 = {}) ⇒ Object
60 61 62 63 |
# File 'lib/fuelcell/help/builder.rb', line 60 def build_desc(cmd, data = {}) data[:desc] = cmd.desc data end |
#build_options(opt_manager, data = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fuelcell/help/builder.rb', line 37 def (opt_manager, data = {}) = [] opt_manager.each do |opt| next if opt.required? << common_opt_data(opt).merge!(banner: opt.) end data[:options] = data end |
#build_usage(script_name, path, cmd, data = {}) ⇒ Hash
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# 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) (cmd.opts, help) build_commands(cmd, path, help) build_desc(cmd, help) help end |