Class: Fuelcell::Help::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/fuelcell/help/builder.rb

Instance Method Summary collapse

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 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 = {}) ⇒ Hash

Parameters:

  • script_name (String)

    name of script you asked help from

  • path (String)

    path of command you need help for

  • cmd (Fuelcell::Action::Command)

    command you need help with

  • data (Hash) (defaults to: {})

    stores the structure of the help content

Returns:

  • (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)
  build_options(cmd.opts, help)
  build_commands(cmd, path, help)
  build_desc(cmd, help)
  help
end