Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a the ability to search upward for a Unity project #233

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions UnitySetup/UnitySetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ function Select-UnitySetupInstance {

<#
.Synopsis
Get the Unity Projects under a specfied folder
Get the Unity Projects relative to a specfied folder
.DESCRIPTION
Recursively discovers Unity projects and their Unity version
.PARAMETER BasePath
Expand All @@ -1389,6 +1389,8 @@ function Select-UnitySetupInstance {
Get-UnityProjectInstance
.EXAMPLE
Get-UnityProjectInstance -BasePath .\MyUnityProjects -Recurse
.EXAMPLE
Get-UnityProjectInstance -BasePath .\SubDirectoyOfAUnityProject -RecurseUp
#>
function Get-UnityProjectInstance {
[CmdletBinding()]
Expand All @@ -1397,27 +1399,48 @@ function Get-UnityProjectInstance {
[string] $BasePath = $PWD,

[parameter(Mandatory = $false)]
[switch] $Recurse
[switch] $Recurse,

[parameter(Mandatory = $false, ParameterSetName = "RecurseUp")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could include this behavior without restricting the others. Is there a strong reason to use the parameter set name?

[switch] $RecurseUp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something about RecurseUp hurts me. Maybe IncludeParent\s??

)

$args = @{
'Path' = $BasePath;
'Filter' = 'ProjectSettings';
'ErrorAction' = 'Ignore';
'Directory' = $true;
}

if ( $Recurse ) {
$args['Recurse'] = $true;
}
switch ($PSCmdlet.ParameterSetName) {
'RecurseUp' {
$current = $BasePath
while (-not [string]::IsNullOrEmpty($current)) {
Get-ChildItem -Path $current @args |
ForEach-Object {
$path = [io.path]::Combine($_.FullName, "ProjectVersion.txt")
if ( Test-Path $path ) {
[UnityProjectInstance]::new((Join-Path $_.FullName "..\" | Convert-Path))
}
}

Get-ChildItem @args |
ForEach-Object {
$path = [io.path]::Combine($_.FullName, "ProjectVersion.txt")
if ( Test-Path $path ) {
[UnityProjectInstance]::new((Join-Path $_.FullName "..\" | Convert-Path))
$current = Split-Path $current -Parent
}
}
default {
$args['Path'] = $BasePath;
if ( $Recurse ) {
$args['Recurse'] = $true;
}

Get-ChildItem @args |
ForEach-Object {
$path = [io.path]::Combine($_.FullName, "ProjectVersion.txt")
if ( Test-Path $path ) {
[UnityProjectInstance]::new((Join-Path $_.FullName "..\" | Convert-Path))
}
}
}
}
}

<#
Expand Down