Skip to content

Commit

Permalink
Add CLI installer
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomorain committed Sep 23, 2019
1 parent 7b64e49 commit ca9f180
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ to a dialog popping up. Feel free to dupe [the radar][5]. 📡

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

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.

Expand Down
3 changes: 1 addition & 2 deletions lib/xcode/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def fetch(url: nil,
progress: nil,
progress_block: nil)
options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH]

uri = URI.parse(url)
output ||= File.basename(uri.path)
output = (Pathname.new(directory) + Pathname.new(output)) if directory
Expand Down Expand Up @@ -329,7 +328,7 @@ def mount(dmg_path)
node.text
end

private
#private

def spaceship
@spaceship ||= begin
Expand Down
3 changes: 2 additions & 1 deletion lib/xcode/install/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class Command < CLAide::Command
require 'xcode/install/list'
require 'xcode/install/select'
require 'xcode/install/selected'
require 'xcode/install/simulators'
require 'xcode/install/tools.rb'
require 'xcode/install/uninstall'
require 'xcode/install/update'
require 'xcode/install/simulators'

self.abstract_command = true
self.command = 'xcversion'
Expand Down
62 changes: 62 additions & 0 deletions lib/xcode/install/tools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
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
2 changes: 1 addition & 1 deletion xcode-install.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
# contains spaceship, which is used for auth and dev portal interactions
spec.add_dependency 'fastlane', '>= 2.1.0', '< 3.0.0'

spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'bundler', '~> 2.0.2'
spec.add_development_dependency 'rake', '~> 10.0'
end

0 comments on commit ca9f180

Please sign in to comment.