diff --git a/lib/gitlab/help.rb b/lib/gitlab/help.rb index c06ad9942..e6a18cbb7 100644 --- a/lib/gitlab/help.rb +++ b/lib/gitlab/help.rb @@ -5,19 +5,35 @@ module Gitlab::Help extend Gitlab::CLI::Helpers def self.get_help(methods,cmd=nil) + help = '' if cmd.nil? || cmd === 'help' - puts actions_table + help = actions_table else - namespace = methods.select {|m| m[:name] === cmd }.map {|m| m[:owner]+'.'+m[:name] }.shift - if namespace - begin - puts `ri -T #{namespace}` - rescue => e - puts e.message + 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 - puts "Unknown command: #{cmd}" + help = "'ri' tool not found in your PATH, please install it to use the help." end end + puts help end end