Class: Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/mygit.rb

Class Method Summary collapse

Class Method Details

.branch_urlObject



91
92
93
# File 'lib/mygit.rb', line 91

def branch_url
  "tree/#{current_branch}"
end

.current_branchObject



87
88
89
# File 'lib/mygit.rb', line 87

def current_branch
  `git rev-parse --abbrev-ref HEAD`
end

.execute(args) ⇒ Object

TODO: Use OptionsParser



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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