class Octocat::CommandLine

Constants

COMMANDS

Attributes

api[R]
command[R]

Public Class Methods

new(arguments) click to toggle source
# File lib/octocat/command_line.rb, line 7
def initialize arguments
  @command = arguments.first
  @api = API.new
end

Public Instance Methods

current_branch() click to toggle source
# File lib/octocat/command_line.rb, line 45
def current_branch
  `git rev-parse --abbrev-ref HEAD`.chomp
end
help() click to toggle source
# File lib/octocat/command_line.rb, line 38
def help
  COMMANDS.each do |command|
    puts "- #{command}"
  end
  puts
end
run() click to toggle source
# File lib/octocat/command_line.rb, line 12
def run
  if command
    run_command
  else
    puts "Octocat Version #{VERSION}"
    help
  end
end
run_command() click to toggle source
# File lib/octocat/command_line.rb, line 21
def run_command
  if command == "open-branch"
    api.open_branch(project, current_branch)
  elsif command == "new-pr"
    api.new_pr(project, current_branch)
  elsif command == "open-pr"
    api.open_pr(project, current_branch)
  elsif command == "compare-branch"
    api.compare_branch(project, current_branch)
  elsif command == "help"
    help
  else
    puts "Unknown Command. The known commands are:"
    help
  end
end

Private Instance Methods

get_project() click to toggle source
# File lib/octocat/command_line.rb, line 61
def get_project
  if git_url.include? "@"
    git_url.split(":", 2).last.gsub(/\.git$/, "")
  else
    URI(git_url).path[1..-1].gsub(/\.git$/, "")
  end
end
git_url() click to toggle source
# File lib/octocat/command_line.rb, line 53
def git_url
  @git_url ||= `git remote show -n origin | grep 'URL' | head -1`.chomp.split(": ", 2).last
end
project() click to toggle source
# File lib/octocat/command_line.rb, line 57
def project
  @project ||= get_project
end