-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathtools.rb
More file actions
62 lines (54 loc) · 1.9 KB
/
tools.rb
File metadata and controls
62 lines (54 loc) · 1.9 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
require 'claide'
require 'spaceship'
module XcodeInstall
class Command
class Tools < Command
self.command = 'tools'
self.summary = 'List or install Xcode CLI tools.'
def self.options
[['--install=name', 'Install simulator beginning with name, e.g. \'iOS 8.4\', \'tvOS 9.0\'.'],
['--force', 'Install even if the same version is already installed.'],
['--no-install', 'Only download DMG, but do not install it.'],
['--no-progress', 'Don’t show download progress.']].concat(super)
end
def initialize(argv)
@install = argv.option('install')
@force = argv.flag?('force', false)
@should_install = argv.flag?('install', true)
@progress = argv.flag?('progress', true)
@installer = XcodeInstall::Installer.new
super
end
def run
@install ? install : list
end
:private
def download(package)
puts("Downloading #{package}")
url = 'https://developer.apple.com/devcenter/download.action?path=' + package
dmg_file = File.basename(url)
Curl.new.fetch(
url: url,
directory: XcodeInstall::CACHE_DIR,
cookies: @installer.spaceship.cookie,
output: dmg_file,
progress: false
)
XcodeInstall::CACHE_DIR + dmg_file
end
def install
dmg_path = download(@install)
puts("Downloaded to from #{dmg_path}")
mount_dir = @installer.mount(dmg_path)
puts("Mounted to #{mount_dir}")
pkg_path = Dir.glob(File.join(mount_dir, '*.pkg')).first
puts("Installing from #{pkg_path}")
prompt = "Please authenticate to install Command Line Tools.\nPassword: "
`sudo -p "#{prompt}" installer -verbose -pkg "#{pkg_path}" -target /`
end
def list
raise NotImplementedError, 'Listing is not implemented'
end
end
end
end