Sha256: 2f577a368fa43f906d33bbbfb6e49d7003e5234ef304898bb2f435efeced6171

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'gitlab'
require 'gitlab/cli_helpers'

module Gitlab::Help
  extend Gitlab::CLI::Helpers

  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitlab-3.3.0 lib/gitlab/help.rb