Skip to content

Commit ca9f180

Browse files
committed
Add CLI installer
1 parent 7b64e49 commit ca9f180

File tree

5 files changed

+67
-5
lines changed

5 files changed

+67
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ to a dialog popping up. Feel free to dupe [the radar][5]. 📡
151151

152152
XcodeInstall normally relies on the Spotlight index to locate installed versions of Xcode. If you use it while
153153
indexing is happening, it might show inaccurate results and it will not be able to see installed
154-
versions on unindexed volumes.
154+
versions on unindexed volumes.
155155

156156
To workaround the Spotlight limitation, XcodeInstall searches `/Applications` folder to locate Xcodes when Spotlight is disabled on the machine, or when Spotlight query for Xcode does not return any results. But it still won't work if your Xcodes are not located under `/Applications` folder.
157157

lib/xcode/install.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def fetch(url: nil,
3131
progress: nil,
3232
progress_block: nil)
3333
options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH]
34-
3534
uri = URI.parse(url)
3635
output ||= File.basename(uri.path)
3736
output = (Pathname.new(directory) + Pathname.new(output)) if directory
@@ -329,7 +328,7 @@ def mount(dmg_path)
329328
node.text
330329
end
331330

332-
private
331+
#private
333332

334333
def spaceship
335334
@spaceship ||= begin

lib/xcode/install/command.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class Command < CLAide::Command
2020
require 'xcode/install/list'
2121
require 'xcode/install/select'
2222
require 'xcode/install/selected'
23+
require 'xcode/install/simulators'
24+
require 'xcode/install/tools.rb'
2325
require 'xcode/install/uninstall'
2426
require 'xcode/install/update'
25-
require 'xcode/install/simulators'
2627

2728
self.abstract_command = true
2829
self.command = 'xcversion'

lib/xcode/install/tools.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
require 'claide'
2+
require 'spaceship'
3+
4+
module XcodeInstall
5+
class Command
6+
class Tools < Command
7+
self.command = 'tools'
8+
self.summary = 'List or install Xcode CLI tools.'
9+
10+
def self.options
11+
[['--install=name', 'Install simulator beginning with name, e.g. \'iOS 8.4\', \'tvOS 9.0\'.'],
12+
['--force', 'Install even if the same version is already installed.'],
13+
['--no-install', 'Only download DMG, but do not install it.'],
14+
['--no-progress', 'Don’t show download progress.']].concat(super)
15+
end
16+
17+
def initialize(argv)
18+
@install = argv.option('install')
19+
@force = argv.flag?('force', false)
20+
@should_install = argv.flag?('install', true)
21+
@progress = argv.flag?('progress', true)
22+
@installer = XcodeInstall::Installer.new
23+
super
24+
end
25+
26+
def run
27+
@install ? install : list
28+
end
29+
end
30+
31+
:private
32+
33+
def download(package)
34+
puts("Downloading #{package}")
35+
url = 'https://developer.apple.com/devcenter/download.action?path=' + package
36+
dmg_file = File.basename(url)
37+
Curl.new.fetch(
38+
url: url,
39+
directory: XcodeInstall::CACHE_DIR,
40+
cookies: @installer.spaceship.cookie,
41+
output: dmg_file,
42+
progress: false
43+
)
44+
XcodeInstall::CACHE_DIR + dmg_file
45+
end
46+
47+
def install
48+
dmg_path = download(@install)
49+
puts("Downloaded to from #{dmg_path}")
50+
mount_dir = @installer.mount(dmg_path)
51+
puts("Mounted to #{mount_dir}")
52+
pkg_path = Dir.glob(File.join(mount_dir, '*.pkg')).first
53+
puts("Installing from #{pkg_path}")
54+
prompt = "Please authenticate to install Command Line Tools.\nPassword: "
55+
`sudo -p "#{prompt}" installer -verbose -pkg "#{pkg_path}" -target /`
56+
end
57+
58+
def list
59+
raise NotImplementedError, 'Listing is not implemented'
60+
end
61+
end
62+
end

xcode-install.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
2727
# contains spaceship, which is used for auth and dev portal interactions
2828
spec.add_dependency 'fastlane', '>= 2.1.0', '< 3.0.0'
2929

30-
spec.add_development_dependency 'bundler', '~> 1.7'
30+
spec.add_development_dependency 'bundler', '~> 2.0.2'
3131
spec.add_development_dependency 'rake', '~> 10.0'
3232
end

0 commit comments

Comments
 (0)