Skip to content

Commit

Permalink
Handling some error cases when calling for help.
Browse files Browse the repository at this point in the history
  • Loading branch information
asedge committed Jun 20, 2014
1 parent 7705b01 commit fee67da
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions lib/gitlab/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fee67da

Please sign in to comment.