Improved Export-FunctionSource + some Docker fixes

Export-FunctionSource to handle Filters and scripts + following Aliases.
Edit-DockerCompose will allow editing of additional files next to the
default docker-compose files.
dcc, dcdown and dcup to work with ProjectPath parameter.
Added ssh.conf to the config.files.json dictionary.
This commit is contained in:
lksz 2020-11-11 16:38:56 -05:00
parent 38dab59d62
commit 1bef8ca119
6 changed files with 51 additions and 11 deletions

View File

@ -1,4 +1,9 @@
[CmdletBinding(SupportsShouldProcess)]param([string[]]$ProjectPath=@($PWD),[switch]$Force) [CmdletBinding(SupportsShouldProcess)]param(
[string[]]$ProjectPath=@($PWD),
[switch]$Force,
[string[]]$AdditionalFiles
)
$local:editCandidates = @('docker-compose.yml','.base.docker-compose.yml') $local:editCandidates = @('docker-compose.yml','.base.docker-compose.yml')
$local:editFiles = @() $local:editFiles = @()
@ -9,6 +14,6 @@ foreach( $local:fileName in $EditCandidates ) {
} }
} }
Edit-TextFile $editFiles Edit-TextFile ($editFiles + $AdditionalFiles)
$editFiles | Select-Object -First 1 | ForEach-Object { docker-compose --file $(Resolve-Path $_) config -q } $editFiles | Select-Object -First 1 | ForEach-Object { docker-compose --file $(Resolve-Path $_) config -q }

View File

@ -371,9 +371,23 @@ param(
$local:src = "" $local:src = ""
foreach ( $local:func in $FunctionName ) { foreach ( $local:func in $FunctionName ) {
$local:funcDef = $null
foreach( $cmd in (Get-Command -All $func) ) {
if( $cmd.CommandType -in @('Function','Filter') ) {
$funcDef = $cmd.Definition
break
} elseif( -$funcDef -and ($cmd.CommandType -in @('Script','ExternalScript')) ) {
$funcDef = Get-Content $cmd.Definition
}
}
if( -not $funcDef ) {
default { throw "Don't know how to handle $func" }
}
if ( -not $NoHeader ) { $src += "`nfunction $func {" } if ( -not $NoHeader ) { $src += "`nfunction $func {" }
$src += "`n" $src += "`n"
$src += $((Get-Command -Type Function $func).Definition)
$src += $funcDef
if ( -not $NoHeader ) { $src += "`n}" } if ( -not $NoHeader ) { $src += "`n}" }
$src += "`n" $src += "`n"
} }

View File

@ -1,3 +1,5 @@
[CmdletBinding(SupportsShouldProcess)]param([string[]]$ProjectPath=@($PWD)) [CmdletBinding(SupportsShouldProcess)]param(
[string[]]$ProjectPath=@($PWD)
)
$ProjectPath | ForEach-Object { docker-compose --file $(Resolve-Path $(Join-Path $_ docker-compose.yml)) config | less } $ProjectPath | ForEach-Object { docker-compose --file $(Resolve-Path $(Join-Path $_ docker-compose.yml)) config | less }

View File

@ -1 +1,9 @@
docker-compose down --timeout=3 --volumes --remove-orphans "$args" [CmdletBinding(SupportsShouldProcess)]param(
[string[]]$ProjectPath=@($PWD),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$CliParams
)
$ProjectPath | ForEach-Object {
docker-compose --file $(Resolve-Path $(Join-Path $_ docker-compose.yml)) down --timeout=3 --volumes --remove-orphans "$CliParams"
}

View File

@ -1,10 +1,19 @@
#[CmdletBinding(SupportsShouldProcess)]param() [CmdletBinding(SupportsShouldProcess)]param(
[string[]]$ProjectPath=@($PWD),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$CliParams
)
$local:dcParams = [string]::Empty $local:dcParams = [string]::Empty
if( $args ) { if( $CliParams ) {
$dcParams = $args | ForEach-Object { $dcParams = $CliParams | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ } if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" } else { "'$($_.Replace( "'", "''" ))'" }
} }
} }
docker-compose up -d --remove-orphans $dcParams && docker-compose logs --follow --tail 10 $dcParams $ProjectPath | ForEach-Object {
$local:dcPath = $(Resolve-Path $(Join-Path $_ docker-compose.yml))
Write-Verbose "docker-compose --file $dcPath up -d --remove-orphans $dcParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams"
docker-compose --file $dcPath up -d --remove-orphans $dcParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams
}

View File

@ -37,6 +37,8 @@
"ssh-pub": "~/.ssh/id_*.pub", "ssh-pub": "~/.ssh/id_*.pub",
"ssh-id": ["~/.ssh/id_ed25519","~/.ssh/id_rsa"], "ssh-id": ["~/.ssh/id_ed25519","~/.ssh/id_rsa"],
"ssh-auth": "~/.ssh/authorized_keys", "ssh-auth": "~/.ssh/authorized_keys",
"ssh-conf": "/etc/ssh/sshd_config", "ssh-known": "~/.ssh/known_hosts",
"ssh" : [ "#ssh-auth", "#ssh-conf", "#ssh-pub", "#ssh-id" ] "ssh-conf": "~/.ssh/config",
"sshd-conf": "/etc/ssh/sshd_config",
"ssh" : [ "#ssh-auth", "#ssh-known", "#ssh-conf", "#sshd-conf", "#ssh-pub", "#ssh-id" ]
} }