2020-11-11 21:38:56 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess)]param(
|
2020-11-25 05:46:33 +00:00
|
|
|
[ArgumentCompleter({ param (
|
|
|
|
$commandName,
|
|
|
|
$parameterName,
|
|
|
|
$wordToComplete,
|
|
|
|
$commandAst,
|
|
|
|
$fakeBoundParameters
|
|
|
|
)
|
|
|
|
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
|
|
|
|
})]
|
2020-11-11 21:38:56 +00:00
|
|
|
[string[]]$ProjectPath=@($PWD),
|
|
|
|
[switch]$Force,
|
|
|
|
[string[]]$AdditionalFiles
|
|
|
|
|
|
|
|
)
|
2020-10-31 21:10:32 +00:00
|
|
|
|
2021-01-14 22:24:29 +00:00
|
|
|
$local:EditCandidates = @('docker-compose.###','.base.docker-compose.###')
|
|
|
|
$local:EditBonus = @('Dockerfile', '.env', '*.env')
|
2020-10-31 21:10:32 +00:00
|
|
|
$local:editFiles = @()
|
2021-01-14 22:24:29 +00:00
|
|
|
foreach( $local:ext in @('.yml', '.yaml') ) {
|
|
|
|
$local:rawEditCandidates = $EditCandidates | ForEach-Object { $_ -replace '\.###',$ext }
|
|
|
|
foreach( $local:fileName in $rawEditCandidates ) {
|
|
|
|
foreach( $local:path in $ProjectPath ) {
|
|
|
|
$local:testPath = Join-Path $path $fileName
|
|
|
|
if( $Force -or $(Test-Path $testPath) ) {
|
|
|
|
$editFiles += $testPath
|
|
|
|
$editFiles += Get-ChildItem $(Join-Path $path '*') -Include $EditBonus -Depth 1
|
|
|
|
}
|
|
|
|
}
|
2020-10-31 21:10:32 +00:00
|
|
|
}
|
2021-01-14 22:24:29 +00:00
|
|
|
if( -not $editFiles ) { continue }
|
|
|
|
|
|
|
|
|
|
|
|
break
|
2020-10-31 21:10:32 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 22:24:29 +00:00
|
|
|
|
2020-11-25 05:46:33 +00:00
|
|
|
Edit-TextFile ($($editFiles | Sort-Object) + $AdditionalFiles)
|
2020-10-31 21:10:32 +00:00
|
|
|
|
2020-11-04 15:58:04 +00:00
|
|
|
$editFiles | Select-Object -First 1 | ForEach-Object { docker-compose --file $(Resolve-Path $_) config -q }
|