class Commands

Public Class Methods

branch_url() click to toggle source
# File lib/mygit.rb, line 91
def branch_url
  "tree/#{current_branch}"
end
current_branch() click to toggle source
# File lib/mygit.rb, line 87
def current_branch
  `git rev-parse --abbrev-ref HEAD`
end
execute(args) click to toggle source

TODO: Use OptionsParser

# File lib/mygit.rb, line 96
def execute args
  cmd = args.shift
  case cmd
  when 'update'
    FileStorage::update
  when 'list'       # dumps a list of all repos found
    Access::list
  when 'find'       # find a repo by name
    pp Access::find args.shift
  when 'clone'      # clone a repo by name
    p = Access::find args.shift
    cmd = "git clone #{p['ssh_url']}"
    system cmd
  when 'open'       # Opens either the current pwd, or a supplied project, GitHub project page in a browser
    opt = args.shift
    opt = File.basename(Dir.getwd) if opt.nil?
    p = Access::find opt
    system "open #{p['html_url']}/#{branch_url}"
  else
    puts 'Unknown or no command given! Options are :-'
    File.open(__FILE__).each_line do |line|
      puts "  " + line.sub('when','').sub('#', '->').gsub('\'','') if line.include? 'when'
      break if line.include? 'else'
    end
  end
end