Module: Gitlab::Help

Extended by:
CLI::Helpers
Defined in:
lib/gitlab/help.rb

Class Method Summary collapse

Methods included from CLI::Helpers

actions_table, confirm_command, excluded_fields, gitlab_helper, multiple_record_table, output_table, required_fields, single_record_table, symbolize_keys, valid_command?, yaml_load_and_symbolize_hash!

Class Method Details

.get_help(methods, cmd = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gitlab/help.rb', line 7

def self.get_help(methods,cmd=nil)
  help = ''

  if cmd.nil? || cmd == 'help'
    help = actions_table
  else
    ri_cmd = `which ri`.chomp

    if $? == 0
      namespace = methods.select {|m| m[:name] === cmd }.map {|m| m[:owner]+'.'+m[:name] }.shift

      if namespace
        begin
          ri_output = `#{ri_cmd} -T #{namespace} 2>&1`.chomp

          if $? == 0
            ri_output.gsub!(/#{cmd}\((.*?)\)/m, cmd+' \1')
            ri_output.gsub!(/Gitlab\./, 'gitlab> ')
            ri_output.gsub!(/Gitlab\..+$/, '')
            ri_output.gsub!(/\,[\s]*/, ' ')
            help = ri_output
          else
            help = "Ri docs not found for #{namespace}, please install the docs to use 'help'"
          end
        rescue => e
          puts e.message
        end
      else
        help = "Unknown command: #{cmd}"
      end
    else
      help = "'ri' tool not found in your PATH, please install it to use the help."
    end
  end

  puts help
end