Skip to content

Commit

Permalink
Add some method documentation and small style fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
asedge committed Feb 20, 2015
1 parent adb28b3 commit da18909
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 3 additions & 5 deletions lib/gitlab/cli_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def confirm_command(cmd)

# Table with available commands.
#
# @return [String]
# @return [Terminal::Table]
def actions_table
owners = method_owners.map {|m| m[:owner].gsub(/Gitlab::(?:Client::)?/,'')}.uniq.sort
methods_c = method_owners.group_by {|m| m[:owner]}
Expand All @@ -103,8 +103,6 @@ def actions_table
end

# Outputs a nicely formatted table or error msg.
#
# @return [String]
def output_table(cmd, args, data)
case data
when Gitlab::ObjectifiedHash
Expand All @@ -118,7 +116,7 @@ def output_table(cmd, args, data)

# Table to display records.
#
# @return [String]
# @return [Terminal::Table]
def record_table(data, cmd, args)
return 'No data' if data.empty?

Expand Down Expand Up @@ -152,7 +150,7 @@ def record_table(data, cmd, args)
end

# Helper function to call Gitlab commands with args.
def gitlab_helper(cmd, args=[])
def gitlab_helper(cmd, args = [])
begin
data = args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd)
rescue => e
Expand Down
12 changes: 10 additions & 2 deletions lib/gitlab/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module Gitlab::Help

class << self

# Returns the (modified) help from the 'ri' command or returns an error.
#
# @return [String]
def get_help(cmd)
cmd_namespace = namespace cmd

Expand All @@ -23,6 +26,9 @@ def get_help(cmd)
end
end

# Finds the location of 'ri' on a system.
#
# @return [String]
def ri_cmd
@ri_cmd if @ri_cmd

Expand All @@ -34,13 +40,15 @@ def ri_cmd
@ri_cmd = which_ri
end

def namespace cmd
# Returns full namespace of a command (e.g. Gitlab::Client::Branches.cmd)
def namespace(cmd)
method_owners.select { |method| method[:name] === cmd }.
map { |method| method[:owner] + '.' + method[:name] }.
shift
end

def change_help_output! cmd, output_str
# Massage output from 'ri'.
def change_help_output!(cmd, output_str)
output_str.gsub!(/#{cmd}\((.*?)\)/m, cmd+' \1')
output_str.gsub!(/Gitlab\./, 'gitlab> ')
output_str.gsub!(/Gitlab\..+$/, '')
Expand Down
8 changes: 5 additions & 3 deletions lib/gitlab/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def start
quit_shell # save history if user presses ctrl-d
end

def parse_input buffer
def parse_input(buffer)
buf = Shellwords.shellwords(buffer)

@command = buf.shift
Expand All @@ -58,15 +58,17 @@ def setup
Readline.completion_append_character = ' '
end

# Gets called when user hits TAB key to do completion
def completion
proc { |str| actions.map(&:to_s).grep(/^#{Regexp.escape(str)}/) }
end

def help cmd=nil
def help(cmd = nil)
cmd.nil? ? actions_table : Gitlab::Help.get_help(cmd)
end

def execute cmd = command, args = arguments
# Execute a given command with arguements
def execute(cmd = command, args = arguments)
if actions.include?(cmd.to_sym)
confirm_command(cmd)
gitlab_helper(cmd, args)
Expand Down

0 comments on commit da18909

Please sign in to comment.