Skip to content
This repository
Eloy Durán October 25, 2012
file 80 lines (66 sloc) 2.153 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
require 'colored'
require 'claide'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/string/strip.rb'

# TODO why does this not automatically occur even though colored is required first?
CLAide::Command.colorize_output = true

module Pod
  class PlainInformative
    include CLAide::Command::InformativeError
  end

  class Command < CLAide::Command
    autoload :ErrorReport, 'cocoapods/command/error_report'
    autoload :Linter, 'cocoapods/command/linter'

    self.abstract_command = true
    self.description = 'CocoaPods, the Objective-C library package manager.'

    def self.options
      [
        ['--silent', 'Show nothing'],
        ['--version', 'Show the version of CocoaPods'],
      ].concat(super)
    end

    def self.parse(argv)
      command = super
      unless command.is_a?(Setup) || ENV['SKIP_SETUP']
        Setup.new(CLAide::ARGV.new([])).run_if_needed
      end
      command
    end

    def self.report_error(error)
      if error.is_a?(Interrupt)
        puts "[!] Cancelled".red
        Config.instance.verbose? ? raise : exit(1)
      else
        puts ErrorReport.report(error)
        exit 1
      end
    end

    def initialize(argv)
      config.silent = argv.flag?('silent')
      super
      config.verbose = self.verbose?
      # TODO we should probably not even load colored unless needed
      String.send(:define_method, :colorize) { |string , _| string } unless self.colorize_output?
    end

    include Config::Mixin

    private

    def verify_podfile_exists!
      unless config.podfile
        raise Informative, "No `Podfile' found in the current working directory."
      end
    end

    def verify_lockfile_exists!
      unless config.lockfile
        raise Informative, "No `Podfile.lock' found in the current working directory, run `pod install'."
      end
    end
  end
end

require 'cocoapods/command/list'
require 'cocoapods/command/outdated'
require 'cocoapods/command/project'
require 'cocoapods/command/push'
require 'cocoapods/command/repo'
require 'cocoapods/command/search'
require 'cocoapods/command/setup'
require 'cocoapods/command/spec'
Something went wrong with that request. Please try again.