Class: Gpr::Commands::Get

Inherits:
Base
  • Object
show all
Defined in:
lib/gpr/commands/get.rb

Constant Summary

Constants included from Gpr

APP_PATH, VERSION

Instance Method Summary collapse

Methods inherited from Base

inherited

Constructor Details

#initialize(thor) ⇒ Get

Returns a new instance of Get.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gpr/commands/get.rb', line 8

def initialize(thor)
  thor.class_eval do
    desc 'get', 'Get a repository'
    def get(param)
      host, user, repository =
        param.match(/.+(\/\/|@)(.+)\.git$/)[2].split(/(:|\/)/).delete_if.with_index { |_c, index| index.odd? }
      path = "#{::Gpr::APP_PATH}/#{host}/#{user}/#{repository}"

      if Dir.exist?(path)
        puts "#{'Warning'.color(:red).style(:underscore)}: #{user}/#{repository} already registered"
        return
      end

      `git clone #{param} #{path}`
    end
  end
end