-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathsimulators.rb
More file actions
68 lines (61 loc) · 2.5 KB
/
simulators.rb
File metadata and controls
68 lines (61 loc) · 2.5 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
63
64
65
66
67
68
require 'claide'
module XcodeInstall
class Command
class Simulators < Command
self.command = 'simulators'
self.summary = 'List or install iOS simulators.'
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.'],
['--retry-count', 'How many times try to download DMG file if downloading fails. Default is 10.']].concat(super)
end
def initialize(argv)
@installed_xcodes = Installer.new.installed_versions
@install = argv.option('install')
@force = argv.flag?('force', false)
@should_install = argv.flag?('install', true)
@progress = argv.flag?('progress', true)
@number_of_try = argv.option('retry-count', '10')
super
end
def run
@install ? install : list
end
end
:private
def install
filtered_simulators = @installed_xcodes.map(&:available_simulators).flatten.uniq(&:name).select do |sim|
sim.name.start_with?(@install)
end
case filtered_simulators.count
when 0
puts "[!] No simulator matching #{@install} was found. Please specify a version from the following available simulators:".ansi.red
list
exit 1
when 1
simulator = filtered_simulators.first
fail Informative, "#{simulator.name} is already installed." if simulator.installed? && !@force
puts "Installing #{simulator.name} for Xcode #{simulator.xcode.bundle_version}..."
fail Informative, "Invalid Retry: `#{@number_of_try} is not positive number.`" if (@number_of_try =~ /\A[0-9]*\z/).nil?
simulator.install(@progress, @should_install, @number_of_try.to_i)
else
puts "[!] More than one simulator matching #{@install} was found. Please specify the full version.".ansi.red
filtered_simulators.each do |candidate|
puts "Xcode #{candidate.xcode.bundle_version} (#{candidate.xcode.path})".ansi.green
puts "xcversion simulators --install=#{candidate.name}"
end
exit 1
end
end
def list
@installed_xcodes.each do |xcode|
puts "Xcode #{xcode.version} (#{xcode.path})".ansi.green
xcode.available_simulators.each do |simulator|
puts simulator.to_s
end
end
end
end
end