Class: U3d::Commands
- Inherits:
-
Object
- Object
- U3d::Commands
- Defined in:
- lib/u3d/commands.rb
Overview
API for U3d, redirecting calls to class they concern rubocop:disable ClassLength
Class Method Summary collapse
-
.console ⇒ Object
rubocop:disable Style/FormatStringToken.
- .credentials(args: []) ⇒ Object
- .credentials_actions ⇒ Object
- .install(args: [], options: {}) ⇒ Object
- .install_dependencies ⇒ Object
- .licenses ⇒ Object
- .list_available(options: {}) ⇒ Object
- .list_installed(options: {}) ⇒ Object
- .local_analyze(args: []) ⇒ Object
-
.move(args: {}, options: {}) ⇒ Object
rubocop:enable Style/FormatStringToken.
- .release_letter_mapping ⇒ Object
- .release_levels ⇒ Object
- .run(options: {}, run_args: []) ⇒ Object
- .uninstall(args: [], options: []) ⇒ Object
Class Method Details
.console ⇒ Object
rubocop:disable Style/FormatStringToken
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/u3d/commands.rb', line 66 def console require 'irb' ARGV.clear IRB.setup(nil) @irb = IRB::Irb.new(nil) IRB.conf[:MAIN_CONTEXT] = @irb.context IRB.conf[:PROMPT][:U3D] = IRB.conf[:PROMPT][:SIMPLE].dup IRB.conf[:PROMPT][:U3D][:RETURN] = "%s\n" @irb.context.prompt_mode = :U3D @irb.context.workspace = IRB::WorkSpace.new(binding) trap 'INT' do @irb.signal_handle end UI.('Welcome to u3d interactive!') catch(:IRB_EXIT) { @irb.eval_input } end |
.credentials(args: []) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/u3d/commands.rb', line 221 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' 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' U3dCore::Globals.use_keychain = true U3dCore::Credentials.new(user: ENV['USER']).forget_credentials(force: true) else credentials_check end end |
.credentials_actions ⇒ Object
217 218 219 |
# File 'lib/u3d/commands.rb', line 217 def credentials_actions %w[add remove check] end |
.install(args: [], options: {}) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/u3d/commands.rb', line 140 def install(args: [], options: {}) version = specified_or_current_project_version(args[0]) UI.user_error!("You cannot use the --operating_system and the --install options together") if [:install] && [:operating_system] os = valid_os_or_current([:operating_system]) cache_versions = cache_versions(os, offline: ![:download]) version = interpret_latest(version, cache_versions) unless cache_versions[version] UI.crash! "No version '#{version}' was found in cache. Either it doesn't exist or u3d doesn't know about it yet. Try refreshing with 'u3d available -f'" return end definition = UnityVersionDefinition.new(version, os, cache_versions) unity = check_unity_presence(version: version) packages = verify_package_names([:packages], definition) || ['Unity'] begin packages = enforce_setup_coherence(packages, , unity, definition) rescue InstallationSetupError return end get_administrative_privileges() if [:install] files = Downloader.fetch_modules(definition, packages: packages, download: [:download]) return unless [:install] Installer.install_modules(files, definition.version, installation_path: [:installation_path]) end |
.install_dependencies ⇒ Object
184 185 186 187 188 189 190 191 |
# File 'lib/u3d/commands.rb', line 184 def install_dependencies unless Helper.linux? UI.important 'u3d dependencies is Linux-only, and not needed on other OS' return end LinuxDependencies.install end |
.licenses ⇒ Object
238 239 240 241 242 |
# File 'lib/u3d/commands.rb', line 238 def licenses U3d::License.licenses.sort_by { |l| l['LicenseVersion'] }.each do |license| UI. "#{license.path}: #{license['LicenseVersion']} #{license.number} #{license['UpdateDate']}" end end |
.list_available(options: {}) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/u3d/commands.rb', line 106 def list_available(options: {}) ver = [:unity_version] os = valid_os_or_current([:operating_system]) rl = [:release_level] central = .fetch(:central, true) cache_versions = cache_versions(os, force_refresh: [:force], central_cache: central) if ver cache_versions = cache_versions.extract(*cache_versions.keys.select { |k| Regexp.new(ver).match(k) }) return UI.error "Version #{ver} doesn't match any in cache" if cache_versions.empty? end vcomparators = cache_versions.keys.map { |k| UnityVersionComparator.new(k) } if rl letter = release_letter_mapping["latest_#{rl}".to_sym] UI. "Filtering available versions with release level '#{rl}' [letter '#{letter}']" vcomparators.select! { |vc| vc.version.parts[3] == letter } end sorted_keys = vcomparators.sort.map { |v| v.version.to_s } show_packages = [:packages] packages = UnityModule.load_modules(sorted_keys, cache_versions, os: os) if show_packages sorted_keys.each do |k| v = cache_versions[k] UI. "Version #{k}: " + v.to_s.cyan.underline next unless show_packages version_packages = packages[k] UI. 'Packages:' version_packages.each { |package| UI. " - #{package.id.capitalize}" } end end |
.list_installed(options: {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/u3d/commands.rb', line 45 def list_installed(options: {}) installer = Installer.create installer.sanitize_installs list = installer.installed_sorted_by_versions 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)" 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. version_format % h packages = u.packages next unless [:packages] && packages && !packages.empty? UI. 'Packages:' packages.each { |pack| UI. " - #{pack}" } end end |
.local_analyze(args: []) ⇒ Object
244 245 246 247 248 249 250 251 252 |
# File 'lib/u3d/commands.rb', line 244 def local_analyze(args: []) raise ArgumentError, 'No files given' if args.empty? raise ArgumentError, "File #{args[0]} does not exist" unless File.exist? args[0] analyzer = LogAnalyzer.new File.open(args[0], 'r') do |f| f.readlines.each { |l| analyzer.parse_line l } end end |
.move(args: {}, options: {}) ⇒ Object
rubocop:enable Style/FormatStringToken
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/u3d/commands.rb', line 86 def move(args: {}, options: {}) long_name = [:long] UI.user_error! "move only supports long version name for now" unless long_name version = args[0] UI.user_error! "Please specify a Unity version" unless version unity = check_unity_presence(version: version) if unity.nil? UI. "Specified version '#{version}' not found." return end if unity.do_not_move? UI.error "Specified version is specicically marked as _do not move_." return end Installer.create.sanitize_install(unity, long: true, dry_run: [:dry_run]) unity.do_not_move!(dry_run: [:dry_run]) # this may fail because of admin rights end |
.release_letter_mapping ⇒ Object
258 259 260 261 262 263 264 265 |
# File 'lib/u3d/commands.rb', line 258 def release_letter_mapping { latest: 'f', latest_stable: 'f', latest_beta: 'b', latest_patch: 'p' } end |
.release_levels ⇒ Object
254 255 256 |
# File 'lib/u3d/commands.rb', line 254 def release_levels %i[stable beta patch] end |
.run(options: {}, run_args: []) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/u3d/commands.rb', line 193 def run(options: {}, run_args: []) version = [:unity_version] runner = Runner.new args_pp = Runner.find_projectpath_in_args(run_args) pp = args_pp pp ||= Dir.pwd up = UnityProject.new(pp) unless version # fall back in project default if we are on a Unity project version = up.editor_version if up.exist? UI.user_error!('Not sure which version of Unity to run. Are you in a Unity5 or later project?') unless version end if up.exist? && args_pp.nil? extra_run_args = ['-projectPath', up.path] run_args = [extra_run_args, run_args].flatten end unity = check_unity_presence(version: version) UI.user_error! "Unity version '#{version}' not found" unless unity runner.run(unity, run_args, raw_logs: [:raw_logs]) end |
.uninstall(args: [], options: []) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/u3d/commands.rb', line 172 def uninstall(args: [], options: []) version = specified_or_current_project_version(args[0]) unity = check_unity_presence(version: version) UI.user_error!("Unity version #{version} is not present and cannot be uninstalled") unless unity get_administrative_privileges() Installer.uninstall(unity: unity) end |