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

Returns a new instance of CloneCommand.



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

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

  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:



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

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

#descriptionObject

:nodoc:



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

def description # :nodoc:
  <<-EOF
The clone command fetches gem metadata from RubyGems.org and clones
the gem's source repository using ghq based on the homepage or
source_code_uri from the gem's metadata.

Examples:
gem clone sinatra
gem clone rails --verbose
gem clone rails --show-url
  EOF
end

#executeObject



36
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
# File 'lib/rubygems/commands/clone_command.rb', line 36

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