Skip to content

Commit

Permalink
Improve code, reorder arguments to match other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lacostej committed Nov 21, 2019
1 parent a0ccb89 commit 96a8eee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
26 changes: 9 additions & 17 deletions lib/u3d/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,7 @@ def install(args: [], options: {})
definition = UnityVersionDefinition.new(version, os, cache_versions)
unity = check_unity_presence(version: version)

packages = options[:packages]

unless packages.nil?
begin
verify_package_names(definition, packages)
rescue StandardError
return
end
else
packages = ['Unity']
end
packages = verify_package_names(options[:packages], definition) || ['Unity']

begin
packages = enforce_setup_coherence(packages, options, unity, definition)
Expand Down Expand Up @@ -283,12 +273,14 @@ def cache_versions(os, offline: false, force_refresh: false, central_cache: true
cache_versions
end

def verify_package_names(definition, packages)
invalid_packages = packages.select { |package| !definition.available_package? package }
unless invalid_packages.empty?
UI.user_error!("Package(s) '#{invalid_packages.join(',')}' are not known. Use #{definition.available_packages.join(',')}")
raise StandardError
def verify_package_names(packages, definition)
unless packages.nil?
invalid_packages = packages.select { |package| !definition.available_package? package }
unless invalid_packages.empty?
raise ArgumentError, "Package(s) '#{invalid_packages.join(',')}' are not known. Use #{definition.available_packages.join(',')}"
end
end
packages
end

def specified_or_current_project_version(version)
Expand Down Expand Up @@ -445,4 +437,4 @@ def get_administrative_privileges(options)
end

class InstallationSetupError < StandardError
end
end
20 changes: 10 additions & 10 deletions spec/u3d/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,16 @@
]
)

expect(U3dCore::UI).to receive(:user_error!).with(/'not.a.package'/)

U3d::Commands.install(
args: ['1.2.3f4'],
options: {
install: false,
download: true,
packages: ['not.a.package']
}
)
expect{
U3d::Commands.install(
args: ['1.2.3f4'],
options: {
install: false,
download: true,
packages: ['not.a.package']
}
)
}.to raise_error ArgumentError, /'not.a.package'/
end
# support downloading the not current platform -> not yet supported
# TODO: Implement me
Expand Down

0 comments on commit 96a8eee

Please sign in to comment.