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
70
71
72
73
74
75
76
77
78
|
# File 'lib/ruby_auto_installer/cli.rb', line 11
def update
@verbose = options[:verbose]
manager_name = options[:manager_name]
if options[:manager_name].nil?
debug "Finding manager..."
if Managers::Asdf.present?
debug "Found asdf version manager"
manager_name = "asdf"
elsif Managers::Rbenv.present?
debug "Found rbenv version manager"
manager_name = "rbenv"
elsif Managers::Rvm.present?
debug "Found rvm version manager"
manager_name = "rvm"
else
raise "Failed to find a version manager"
end
end
debug "Attempting to use #{manager_name} version manager"
manager = load_manager(manager_name)
debug "Updating #{manager_name}"
manager.update
debug "Currently installed versions:"
installed = strip_lines(manager.installed_versions)
debug installed
debug "Available versions:"
available = strip_lines(standard_releases_only(manager.all_versions))
debug available
if options[:greedy].nil?
latest = []
available.sort_by! { |version| Gem::Version.new(version) }
loop do
last = available.last
latest << last
available.reject! { |version| version[0..2] == last[0..2] }
break if available.empty?
end
available = latest
end
debug "Versions to be installed:"
install_versions = missing_releases(installed, available)
unless options[:min_version].nil?
install_versions.reject! { |version| version <= options[:min_version] }
end
debug install_versions
install_versions.each do |version|
if options[:dry_run]
puts "DRY RUN: Would install #{version}"
else
manager.install(version)
end
end
manager.refresh
puts "All done!"
end
|