Class: Gem::Commands::CloneCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/clone_command.rb

Instance Method Summary collapse

Constructor Details

#initializeCloneCommand



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rubygems/commands/clone_command.rb', line 8

def initialize
  super 'clone', 'Clone a gem repository using git goget, ghq, or git'

  add_option('-v', '--verbose', 'Show verbose output') do |value, options|
    options[:verbose] = true
  end

  add_option('-u', '--show-url', 'Show repository URL without cloning') do |value, options|
    options[:show_url] = true
  end
end

Instance Method Details

#argumentsObject

:nodoc:



20
21
22
# File 'lib/rubygems/commands/clone_command.rb', line 20

def arguments # :nodoc:
  "GEM_NAME        name of gem to clone"
end

#descriptionObject

:nodoc:



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubygems/commands/clone_command.rb', line 24

def description # :nodoc:
  "The clone command fetches gem metadata from RubyGems.org and clones\nthe gem's source repository using git goget (preferred), ghq, or git\nbased on the homepage or source_code_uri from the gem's metadata.\n\nExamples:\ngem clone sinatra\ngem clone rails --verbose\ngem clone rails --show-url\n  EOF\nend\n"

#executeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubygems/commands/clone_command.rb', line 37

def execute
  gem_name = get_one_gem_name

  say "Fetching gem metadata for '#{gem_name}'..." if options[:verbose]

  gem_info = fetch_gem_info(gem_name)

  if gem_info.nil?
    alert_error "Could not find gem '#{gem_name}'"
    terminate_interaction 1
  end

  repository_url = extract_repository_url(gem_info)

  if repository_url.nil?
    alert_error "Could not find repository URL for gem '#{gem_name}'"
    terminate_interaction 1
  end

  say "Found repository URL: #{repository_url}" if options[:verbose]

  if options[:show_url]
    say repository_url
  else
    clone_repository(repository_url)
  end
end