dco should handle yaml extensions on top of yml

This commit is contained in:
Gal Szkolnik 2021-02-20 13:09:38 -05:00
parent 22d1b7a1bc
commit c8869ae393
2 changed files with 29 additions and 14 deletions

View File

@ -12,9 +12,9 @@ class DockerContainer { #: System.Management.Automation.IValidateSetValuesGenera
} }
class DockerComposeDirs { #: System.Management.Automation.IValidateSetValuesGenerator { class DockerComposeDirs { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) { static [string[]] _GetValidValues([string]$wordToComplete,[string]$Path,[bool]$Strict) {
$local:possibleValues = $( $local:possibleValues = $(
Get-ChildItem -Directory -Depth 3 | Get-ChildItem -LiteralPath $Path -Directory -Depth 3 |
Where-Object { $_ | Where-Object { $_ |
Get-ChildItem -Include 'docker-compose.y*l' | Get-ChildItem -Include 'docker-compose.y*l' |
Where-Object Extension -in '.yml','.yaml' Where-Object Extension -in '.yml','.yaml'
@ -25,6 +25,10 @@ class DockerComposeDirs { #: System.Management.Automation.IValidateSetValuesGene
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict ); return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
} }
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
return [DockerComposeDirs]::_GetValidValues($wordToComplete,'.',$true)
}
[String[]] GetValidValues() { [String[]] GetValidValues() {
return [DockerComposeDirs]::_GetValidValues('',$true) return [DockerComposeDirs]::_GetValidValues('',$true)
} }

View File

@ -64,19 +64,27 @@ if( $CliParams[0] -is [string] ) {
$CliParams = @($CliParams,@($null)) $CliParams = @($CliParams,@($null))
} }
$local:dcPathList = $ProjectPath | ForEach-Object { $local:ext = ".yml"
if( (Test-Path (Join-Path $_ 'docker-compose.yml')) -and -not $Recurse ) { $local:dcPathList = @()
Resolve-Path $_ $ProjectPath | ForEach-Object {
} elseif( $Recurse ) { while( $true ) {
$local:gciParams = [ordered]@{ if( (Test-Path (Join-Path $_ "docker-compose$ext")) -and -not $Recurse ) {
Recurse = $true $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( $Depth ) { if( ($dcPathList -and -not $Recure) -or $ext -eq '.yaml' ) {
$gciParams.Depth = $Depth break
} }
Get-ChildItem -Path $_ -Include 'docker-compose.yml' @gciParams | $ext = '.yaml'
Select-Object -ExpandProperty Directory |
Where-Object { $Force -or -not (Test-Path $(Join-Path $_ .noauto.all)) }
} }
} }
if( -not $dcPathList ) { return } if( -not $dcPathList ) { return }
@ -106,7 +114,10 @@ foreach( $local:p in $CliParams ) {
} }
$dcPathList | ForEach-Object { $dcPathList | ForEach-Object {
$local:dcPath = Join-Path $_ 'docker-compose.yml' $local:dcPath = Join-Path $_ 'docker-compose.yaml'
if( -not (Test-Path $dcPath) ) {
$dcPath = Join-Path $_ 'docker-compose.yml'
}
if( -not (Test-Path $dcPath) ) { if( -not (Test-Path $dcPath) ) {
if( $Recurse ) { return } if( $Recurse ) { return }
else { throw "ERROR: dcPath ($dcPath) does not exists" } else { throw "ERROR: dcPath ($dcPath) does not exists" }