class Pod::Command::Repo::Add

Public Class Methods

new(argv) click to toggle source
Calls superclass method Pod::Command::new
# File lib/cocoapods/command/repo/add.rb, line 24
def initialize(argv)
  @name = argv.shift_argument
  @url = argv.shift_argument
  @branch = argv.shift_argument
  @progress = argv.flag?('progress')
  super
end
options() click to toggle source
Calls superclass method Pod::Command::options
# File lib/cocoapods/command/repo/add.rb, line 18
def self.options
  [
    ['--progress', 'Show the progress of cloning the spec repository'],
  ].concat(super)
end

Public Instance Methods

run() click to toggle source
# File lib/cocoapods/command/repo/add.rb, line 43
def run
  section = "Cloning spec repo `#{@name}` from `#{@url}`"
  section << " (branch `#{@branch}`)" if @branch
  UI.section(section) do
    create_repos_dir
    clone_repo
    checkout_branch
    config.sources_manager.sources([dir.basename.to_s]).each(&:verify_compatibility!)
  end
end
validate!() click to toggle source
Calls superclass method
# File lib/cocoapods/command/repo/add.rb, line 32
def validate!
  super
  unless @name && @url
    help! 'Adding a repo needs a `NAME` and a `URL`.'
  end
  if @name == 'trunk'
    raise Informative,
          "Repo name `trunk` is reserved for CocoaPods' main spec repo accessed via CDN."
  end
end

Private Instance Methods

checkout_branch() click to toggle source

Checks out the branch of the git spec-repo if provided.

@return [void]

# File lib/cocoapods/command/repo/add.rb, line 96
def checkout_branch
  Dir.chdir(dir) { git!('checkout', @branch) } if @branch
end
clone_repo() click to toggle source

Clones the git spec-repo according to parameters passed to the command.

@return [void]

# File lib/cocoapods/command/repo/add.rb, line 75
def clone_repo
  changes = if @progress
              { :verbose => true }
            else
              {}
            end

  config.with_changes(changes) do
    Dir.chdir(config.repos_dir) do
      command = ['clone', @url]
      command << '--progress' if @progress
      command << '--' << @name
      git!(command)
    end
  end
end
create_repos_dir() click to toggle source

Creates the repos directory specified in the configuration by `config.repos_dir`.

@return [void]

@raise If the directory cannot be created due to a system error.

# File lib/cocoapods/command/repo/add.rb, line 63
def create_repos_dir
  config.repos_dir.mkpath
rescue => e
  raise Informative, "Could not create '#{config.repos_dir}', the CocoaPods repo cache directory.\n" \
    "#{e.class.name}: #{e.message}"
end