[CmdletBinding(SupportsShouldProcess)]param( [Parameter(ParameterSetName="On",Mandatory)] [switch]$On, [Parameter(ParameterSetName="Off",Mandatory)] [switch]$Off, [Parameter(ParameterSetName="Query",Mandatory)] [switch]$NoChange, [switch]$Recurse, [int]$Depth=1, [Parameter(ParameterSetName="On",Position = 0, ValueFromRemainingArguments)] [Parameter(ParameterSetName="Off",Position = 0, ValueFromRemainingArguments)] [Parameter(ParameterSetName="Toggle",Position = 0, ValueFromRemainingArguments)] [Parameter(ParameterSetName="Query",Position = 0, ValueFromRemainingArguments)] [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})] [string[]]$ProjectPath ) if( -not $ProjectPath ) { $ProjectPath=@($PWD) } $local:ext = ".yml" $local:dcPathList = @() $ProjectPath | ForEach-Object { while( $true ) { if( (Test-Path (Join-Path $_ "docker-compose$ext")) -and -not $Recurse ) { $dcPathList += Resolve-Path $_ } elseif( $Recurse ) { $local:gciParams = [ordered]@{ Recurse = $true } if( $Depth ) { $gciParams.Depth = $Depth } $dcPathList += Get-ChildItem -Path $_ -Include "docker-compose$ext" @gciParams | Select-Object -ExpandProperty Directory # | # Where-Object { $Force -or -not (Test-Path $(Join-Path $_ .noauto.all)) } } if( ($dcPathList -and -not $Recure) -or $ext -eq '.yaml' ) { break } $ext = '.yaml' } } if( -not $dcPathList ) { return } $dcPathList | ForEach-Object { $local:NoAutoPath = $(Join-Path $_ '.noauto.all') $local:NoAutoOffPath = "${NoAutoPath}.off" $local:IsNoAuto = Test-Path $NoAutoPath $local:IsNoAutoOff = Test-Path $NoAutoOffPath if( ($NoChange -and $IsNoAuto) -or (-not $NoChange -and ($Off -or (-not $On -and -not $IsNoAuto)) ) ) { if( $IsNoAutoOff ) { Move-Item $NoAutoOffPath $NoAutoPath } elseif( -not $IsNoAuto -and -not $NoChange ) { $null = New-Item -ItemType File -Path $NoAutoPath -Value "" } Write-Host -ForegroundColor Magenta -NoNewline "Off" } elseif( $NoChange -or $On -or (-not $Off -and $IsNoAuto) ) { if( $IsNoAuto -and -not $NoChange ) { Move-Item $NoAutoPath $NoAutoOffPath } Write-Host -ForegroundColor Gree -NoNewline "On " } Write-Host -ForegroundColor Cyan " $("$_".Replace($PWD.Path,'').Substring(1))" }