lib/u3d/commands.rb in u3d-0.9.2 vs lib/u3d/commands.rb in u3d-0.9.3
- old
+ new
@@ -40,18 +40,18 @@
if list.empty?
UI.important 'No Unity version installed'
return
end
# version -> installations
- arraym = list.map{|a| [a.version, a]}
+ arraym = list.map { |a| [a.version, a] }
map = Hash[*arraym.flatten]
# sorted versions
vcomparators = map.keys.map { |k| UnityVersionComparator.new(k) }
sorted_keys = vcomparators.sort.map { |v| v.version.to_s }
sorted_keys.each do |k|
u = map[k]
- UI.message "Version #{u.version}\t(#{u.path})"
+ UI.message "%-*s%s" % [30, "Version #{u.version}", " (#{u.path})"]
packages = u.packages
next unless options[:packages] && packages && !packages.empty?
UI.message 'Packages:'
packages.each { |pack| UI.message " - #{pack}" }
end
@@ -112,15 +112,12 @@
os = U3dCore::Helper.operating_system
cache = Cache.new(force_os: os)
versions = cache[os.id2name]['versions']
version = interpret_latest(version, versions)
- unless packages.include?('Unity')
- unity = check_unity_presence(version: version)
- return unless unity
- options[:installation_path] ||= unity.path if Helper.windows?
- end
+ unity = check_unity_presence(version: version)
+ return unless enforce_setup_coherence(packages, options, unity)
U3d::Globals.use_keychain = true if options[:keychain] && Helper.mac?
unless options[:no_install]
UI.important 'Root privileges are required'
@@ -154,22 +151,20 @@
UI.user_error!('Please specify a version') if args.empty?
version = args[0]
packages = packages_with_unity_first(options)
- unless packages.include?('Unity')
- unity = check_unity_presence(version: version)
- return unless unity
- options[:installation_path] ||= unity.path if Helper.windows?
- end
+ os = U3dCore::Helper.operating_system
+ unity = check_unity_presence(version: version)
+ return unless enforce_setup_coherence(packages, options, unity)
+
U3d::Globals.use_keychain = true if options[:keychain] && Helper.mac?
UI.important 'Root privileges are required'
raise 'Could not get administrative privileges' unless U3dCore::CommandExecutor.has_admin_privileges?
- os = U3dCore::Helper.operating_system
files = []
if os == :linux
UI.important 'Option -a | --all not available for Linux' if options[:all]
UI.important 'Option -p | --packages not available for Linux' if options[:packages]
downloader = Downloader::LinuxDownloader
@@ -216,11 +211,11 @@
def credentials_actions
%w(add remove check)
end
- def credentials(args: [], options: {})
+ def credentials(args: [], _options: {})
action = args[0]
raise "Please specify an action to perform, one of #{credentials_actions.join(',')}" unless action
raise "Unknown action '#{action}'. Use one of #{credentials_actions.join(',')}" unless credentials_actions.include? action
if action == 'add'
U3dCore::Globals.use_keychain = true
@@ -295,15 +290,38 @@
def check_unity_presence(version: nil)
installed = Installer.create.installed
unity = installed.find { |u| u.version == version }
if unity.nil?
- UI.error "Version #{version} of Unity is not installed yet. Please install it first before installing any other module"
+ UI.verbose "Version #{version} of Unity is not installed yet"
else
UI.verbose "Unity #{version} is installed at #{unity.path}"
return unity
end
nil
+ end
+
+ def enforce_setup_coherence(packages, options, unity)
+ if unity
+ UI.important "Unity #{unity.version} is already installed"
+ return false if Helper.linux?
+ if packages.include?('Unity')
+ UI.important 'Ignoring Unity module, it is already installed'
+ packages.delete('Unity')
+ options[:installation_path] ||= unity.path if Helper.windows?
+ end
+ if unity.packages
+ unity.packages.each do |pack|
+ UI.important "Ignoring #{pack} module, it is already installed" if packages.delete(pack)
+ end
+ end
+ else
+ unless packages.include?('Unity')
+ UI.error "Please install Unity #{unity.version} before any of its packages"
+ return false
+ end
+ end
+ true
end
end
end
end