/
command.rb
118 lines (103 loc) · 3.08 KB
/
command.rb
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require 'colored'
require 'claide'
module Pod
class PlainInformative
include CLAide::InformativeError
end
class Command < CLAide::Command
require 'cocoapods/command/help'
require 'cocoapods/command/inter_process_communication'
require 'cocoapods/command/lib'
require 'cocoapods/command/list'
require 'cocoapods/command/outdated'
require 'cocoapods/command/podfile_info'
require 'cocoapods/command/project'
require 'cocoapods/command/push'
require 'cocoapods/command/repo'
require 'cocoapods/command/search'
require 'cocoapods/command/setup'
require 'cocoapods/command/spec'
self.abstract_command = true
self.default_subcommand = 'install'
self.command = 'pod'
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 SourcesManager.master_repo_functional? || command.is_a?(Setup) || command.is_a?(Repo::Add) || ENV['SKIP_SETUP']
Setup.new(CLAide::ARGV.new([])).run
end
command
end
def self.run(argv)
argv = CLAide::ARGV.new(argv)
if argv.flag?('version')
puts VERSION
exit!(0)
end
super(argv)
UI.print_warnings
end
def self.report_error(exception)
if exception.is_a?(Interrupt)
puts "[!] Cancelled".red
Config.instance.verbose? ? raise : exit(1)
else
if ENV['COCOA_PODS_ENV'] != 'development'
puts UI::ErrorReport.report(exception)
exit 1
else
raise exception
end
end
end
# @todo If a command is run inside another one some settings which where
# true might return false.
#
# @todo We should probably not even load colored unless needed.
#
# @todo Move silent flag to CLAide.
#
# @note It is important that the commands don't override the default
# settings if their flag is missing (i.e. their value is nil)
#
def initialize(argv)
super
config.silent = argv.flag?('silent', config.silent)
config.verbose = self.verbose? unless self.verbose.nil?
unless self.colorize_output?
String.send(:define_method, :colorize) { |string , _| string }
end
end
#-------------------------------------------------------------------------#
include Config::Mixin
private
# Checks that the podfile exists.
#
# @raise If the podfile does not exists.
#
# @return [void]
#
def verify_podfile_exists!
unless config.podfile
raise Informative, "No `Podfile' found in the current working directory."
end
end
# Checks that the lockfile exists.
#
# @raise If the lockfile does not exists.
#
# @return [void]
#
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