Sha256: 63ee3ffa35a62ffc3976de020436bd690e4dce35addb223a6d6a695702949897

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 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}\((.*)\)/, cmd+' \1')
              ri_output.gsub!(/Gitlab\./, 'gitlab> ')
              ri_output.gsub!(/Gitlab\..+$/, '')
              ri_output.gsub!(/\,/, '')
              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.2.0 lib/gitlab/help.rb