forked from inket/update_xcode_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.rb
69 lines (54 loc) · 1.42 KB
/
cli.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
module CLI
def self.dry_run?
ARGV.include?('-d') || ARGV.include?('--dry-run')
end
def self.install_launch_agent?
ARGV.include?('--install-launch-agent')
end
def self.uninstall_launch_agent?
ARGV.include?('--uninstall-launch-agent')
end
def self.unsign_xcode?
ARGV.include?('--unsign')
end
def self.restore_xcode?
ARGV.include?('--restore')
end
def self.no_colors?
ARGV.include?('--no-colors')
end
def self.non_interactive?
ARGV.include?('--non-interactive')
end
def self.codesign_exists?
`which codesign` && $CHILD_STATUS.exitstatus == 0
end
def self.chown_if_required(path)
return yield if File.owned?(path)
puts
puts "* Changing ownership of #{path} (will be restored after)".colorize(:light_blue)
previous_owner = File.stat(path).uid
system("sudo chown $(whoami) \"#{path}\"")
raise "Could not change ownership of #{path}" unless File.owned?(path)
result = yield
system("sudo chown #{previous_owner} \"#{path}\"")
puts "* Restored ownership of #{path}".colorize(:light_blue)
result
end
{
title: :blue,
process: :light_blue,
warning: :yellow,
error: :red,
success: :green
}.each do |type, color|
if CLI.no_colors?
define_method type.to_sym do |str| puts str end
else
define_method type.to_sym do |str| puts str.colorize(color) end
end
end
def separator
puts
end
end