lib/u3d/commands.rb in u3d-1.2.3 vs lib/u3d/commands.rb in u3d-1.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
## --- BEGIN LICENSE BLOCK ---
# Copyright (c) 2016-present WeWantToKnow AS
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -35,11 +37,11 @@
require 'u3d_core/credentials'
require 'fileutils'
module U3d
# API for U3d, redirecting calls to class they concern
- # rubocop:disable ClassLength
+ # rubocop:disable Metrics/ClassLength
class Commands
using ::CoreExtensions::Extractable
class << self
def list_installed(options: {})
@@ -49,22 +51,22 @@
if list.empty?
UI.important 'No Unity version installed'
return
end
list.each do |u|
- version_format = "Version %-15{version} [%<build_number>s] %<do_not_move>s(%<root_path>s)"
+ version_format = "Version %-15<version>s [%<build_number>s] %<do_not_move>s(%<root_path>s)"
do_not_move = u.do_not_move? ? '!'.red.bold : ' '
h = { version: u.version, build_number: u.build_number, root_path: u.root_path, do_not_move: do_not_move }
UI.message version_format % h
packages = u.packages
next unless options[:packages] && packages && !packages.empty?
+
UI.message 'Packages:'
packages.each { |pack| UI.message " - #{pack}" }
end
end
- # rubocop:disable Style/FormatStringToken
def console
require 'irb'
ARGV.clear
IRB.setup(nil)
@irb = IRB::Irb.new(nil)
@@ -79,11 +81,10 @@
UI.message('Welcome to u3d interactive!')
catch(:IRB_EXIT) { @irb.eval_input }
end
- # rubocop:enable Style/FormatStringToken
def move(args: {}, options: {})
long_name = options[:long]
UI.user_error! "move only supports long version name for now" unless long_name
@@ -129,10 +130,11 @@
sorted_keys.each do |k|
v = cache_versions[k]
UI.message "Version #{k}: " + v.to_s.cyan.underline
next unless show_packages
+
version_packages = packages[k]
UI.message 'Packages:'
version_packages.each { |package| UI.message " - #{package.id.capitalize}" }
end
end
@@ -164,10 +166,11 @@
get_administrative_privileges(options) if options[:install]
files = Downloader.fetch_modules(definition, packages: packages, download: options[:download])
return unless options[:install]
+
Installer.install_modules(files, definition.version, installation_path: options[:installation_path])
end
def uninstall(args: [], options: [])
version = specified_or_current_project_version(args[0])
@@ -220,16 +223,18 @@
def credentials(args: [])
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'
+
+ case action
+ when 'add'
U3dCore::Globals.use_keychain = true
# credentials = U3dCore::Credentials.new(user: ENV['USER'])
# credentials.login # ask password
UI.error 'Invalid credentials' unless U3dCore::CommandExecutor.has_admin_privileges?
- elsif action == 'remove'
+ when 'remove'
U3dCore::Globals.use_keychain = true
U3dCore::Credentials.new(user: ENV['USER']).forget_credentials(force: true)
else
credentials_check
end
@@ -267,12 +272,11 @@
private
def cache_versions(os, offline: false, force_refresh: false, central_cache: true)
cache = Cache.new(force_os: os, offline: offline, force_refresh: force_refresh, central_cache: central_cache)
cache_os = cache[os.id2name] || {}
- cache_versions = cache_os['versions'] || {}
- cache_versions
+ cache_os['versions'] || {}
end
def verify_package_names(packages, definition)
unless packages.nil?
invalid_packages = packages.reject { |package| definition.available_package? package }
@@ -416,10 +420,11 @@
def can_install?(package_name, unity, definition, installing)
package = definition[package_name]
return true unless package.depends_on
return true if unity.package_installed?(package.depends_on)
+
installing.map { |other| definition[other] }.any? do |other|
other.id == package.depends_on || other.name == package.depends_on
end
end
@@ -428,10 +433,10 @@
UI.important 'Root privileges are required'
raise 'Could not get administrative privileges' unless U3dCore::CommandExecutor.has_admin_privileges?
end
end
end
- # rubocop:enable ClassLength
+ # rubocop:enable Metrics/ClassLength
end
class InstallationSetupError < StandardError
end