Added DockerCompose completion + fixes

This commit is contained in:
lksz 2021-03-23 01:06:49 -04:00
parent b5b5702b17
commit d441492cf0
24 changed files with 207 additions and 147 deletions

View File

@ -35,14 +35,10 @@ process {
} }
$p = $p -replace '#C-A#','*' -replace '#C-Q#','?' -replace '#C-#','#C-' $p = $p -replace '#C-A#','*' -replace '#C-Q#','?' -replace '#C-#','#C-'
if( $Expand ) { if( $p -match '\*|\?' -and $Expand ) {
$p = $p | ForEach-Object { $p = $p | Where-Object { Test-Path $_ } |
if( Test-Path $p ) { Get-Item -Force |
$p | Get-Item -Force | Select-Object -ExpandProperty FullName Select-Object -ExpandProperty FullName
} elseif( -not $Expand ) {
$p
}
}
} }
$p $p

1
base/_ls.ps1 Normal file
View File

@ -0,0 +1 @@
env ls $args

1
base/ls.ps1 Normal file
View File

@ -0,0 +1 @@
Get-ChildItem -Force $args

View File

@ -1,36 +0,0 @@
class DockerContainer { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
$local:possibleValues = $(
docker ps -a --no-trunc --format "{{.Names}}"
)
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}
[String[]] GetValidValues() {
return [DockerContainer]::_GetValidValues('',$true)
}
}
class DockerComposeDirs { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[string]$Path,[bool]$Strict) {
$local:possibleValues = $(
Get-ChildItem -LiteralPath $Path -Directory -Depth 3 |
Where-Object { $_ |
Get-ChildItem -Include 'docker-compose.y*l' |
Where-Object Extension -in '.yml','.yaml'
} | ForEach-Object {
$_.FullName.Replace($(Join-Path $PWD ""),'')
}
)
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
return [DockerComposeDirs]::_GetValidValues($wordToComplete,'.',$true)
}
[String[]] GetValidValues() {
return [DockerComposeDirs]::_GetValidValues('',$true)
}
}

View File

@ -0,0 +1,6 @@
function cd-{cd -}
function cd..{cd ..}
function cd...{cd ../..}
Set-Alias '..' 'cd..'
Set-Alias '...' 'cd...'

1
docker/Aliases/cp.ps1 Normal file
View File

@ -0,0 +1 @@
Copy-Item

1
docker/Aliases/mv.ps1 Normal file
View File

@ -0,0 +1 @@
Move-Item

1
docker/Aliases/rm.ps1 Normal file
View File

@ -0,0 +1 @@
Remove-Item

View File

@ -1,13 +1,5 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD), [string[]]$ProjectPath=@($PWD),
[switch]$Force, [switch]$Force,
[string[]]$AdditionalFiles [string[]]$AdditionalFiles

View File

@ -1,19 +1,12 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath, [string[]]$ProjectPath,
[switch]$Recurse, [switch]$Recurse,
[int]$Depth=1, [int]$Depth=1,
[switch]$Force, [switch]$Force,
[switch]$OneLine, [switch]$OneLine,
[Parameter(Position = 0, ValueFromRemainingArguments = $true, mandatory)] [Parameter(Position = 0, mandatory, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList $args})]
[array]$CliParams [array]$CliParams
) )
@ -110,7 +103,7 @@ foreach( $local:p in $CliParams ) {
} }
$local:dcParams=@() $local:dcParams=@()
$local:dcParams = $p | Where-Object { $_ } | ForEach-Object { $local:dcParams += $p | Where-Object { $_ } | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ } if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" } else { "'$($_.Replace( "'", "''" ))'" }
} }

View File

@ -1,13 +1,5 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD), [string[]]$ProjectPath=@($PWD),
[switch]$TestOnly [switch]$TestOnly
) )

View File

@ -1,22 +1,15 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath, [string[]]$ProjectPath,
[switch]$Recurse, [switch]$Recurse,
[int]$Depth=1, [int]$Depth=1,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('down'))})]
[array]$CliParams=@('--timeout=3','--volumes','--remove-orphans') [array]$CliParams=@('--timeout=3','--volumes','--remove-orphans')
) )
if( -not $CliParams -or $CliParams[0] -is [string] ) { $CliParams = @($CliParams,@($null)) } if( -not $CliParams -or $CliParams[0] -is [string] ) { $CliParams = @($CliParams,@($null)) }
$CliParams[0] = @('&','down') + $CliParams[0] $CliParams[0] = @('&') + $CliParams[0]
Invoke-DockerCompose -ProjectPath $ProjectPath -CliParams $CliParams -Recurse:$Recurse -Depth $Depth Invoke-DockerCompose -ProjectPath $ProjectPath -dcCommand 'down' -CliParams $CliParams -Recurse:$Recurse -Depth $Depth

View File

@ -1,15 +1,8 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD), [string[]]$ProjectPath=@($PWD),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@("logs"))})]
[array]$CliParams [array]$CliParams
) )

View File

@ -1,15 +1,8 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD), [string[]]$ProjectPath=@($PWD),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('logs'))})]
[array]$CliParams [array]$CliParams
) )

View File

@ -1,15 +1,8 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD), [string[]]$ProjectPath=@($PWD),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('run'))})]
[array]$CliParams=@('--rm') [array]$CliParams=@('--rm')
) )

View File

@ -1,15 +1,8 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD), [string[]]$ProjectPath=@($PWD),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('restart'))})]
[array]$CliParams [array]$CliParams
) )

View File

@ -1,22 +1,18 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath, [string[]]$ProjectPath,
[switch]$Recurse, [switch]$Recurse,
[int]$Depth=1, [int]$Depth=1,
[switch]$NoLogs, [switch]$NoLogs,
[switch]$NoPull, [switch]$NoPull,
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('pull'))})]
[array]$PullParams, [array]$PullParams,
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('logs'))})]
[array]$LogsParams, [array]$LogsParams,
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('up'))})]
[array]$UpParams=@('-d','--remove-orphans'), [array]$UpParams=@('-d','--remove-orphans'),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('up'))})]
[array]$Containers [array]$Containers
) )

View File

@ -1,22 +1,18 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath, [string[]]$ProjectPath,
[switch]$Recurse, [switch]$Recurse,
[int]$Depth=1, [int]$Depth=1,
[switch]$NoLogs, [switch]$NoLogs,
[switch]$NoPull, [switch]$NoPull,
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('pull'))})]
[array]$PullParams, [array]$PullParams,
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('logs'))})]
[array]$LogsParams, [array]$LogsParams,
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('up'))})]
[array]$UpParams=@('--detach','--remove-orphans'), [array]$UpParams=@('--detach','--remove-orphans'),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('up'))})]
[array]$Containers [array]$Containers
) )

View File

@ -1,15 +1,8 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param ( [ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD), [string[]]$ProjectPath=@($PWD),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeCompleter -ArgumentList ($args+@('exec'))})]
[array]$CliParams [array]$CliParams
) )

View File

@ -0,0 +1,162 @@
class DockerContainers { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
$local:possibleValues = $(
docker container ls -a --no-trunc --format "{{.Names}}"
)
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}
[String[]] GetValidValues() {
return [DockerContainers]::_GetValidValues('',$true)
}
}
class DockerImages { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
$local:possibleValues = $(
docker image ls --format "{{.Repository}}"
)
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}
[String[]] GetValidValues() {
return [DockerImages]::_GetValidValues('',$true)
}
}
class DockerNetworks {
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
$local:possibleValues = $(
docker network ls --no-trunc --format "{{.Name}}"
)
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}
[String[]] GetValidValues() {
return [DockerNetworks]::_GetValidValues('',$true)
}
}
class DockerComposeCommands { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] $cachedCommands = @()
static [string[]] _GetValidValues([string]$wordToComplete,[string]$subcommand,[bool]$Strict) {
$local:gate = $false
$local:possibleValues = $(
docker-compose $subcommand --help | Out-String -Stream |
ForEach-Object {
if( $wordToComplete -match '^-' ) {
if( $_ -match "^ *(-.*) (\w.*)$" ) {
$matches[1] -split ', ' | ForEach-Object { $_ -split ' ' | Select-Object -First 1 }
}
} elseif( -not $gate ) {
if ( $_.trim() -eq 'Commands:' ) { $gate = $true }
} else {
$null = $_ -match '^\W+(\w+)\W+(.+)$';
$Matches[1];
}
}
)
[DockerComposeCommands]::cachedCommands = $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
return [DockerComposeCommands]::cachedCommands;
}
[String[]] GetValidValues() {
return [DockerComposeCommands]::_GetValidValues('',$true)
}
}
$global:_DockerComposeCommandCompleter = [ScriptBlock]{
param(
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeCommands]::_GetValidValues($wordToComplete,"",$true)
}
class DockerComposeServices { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[string]$Path,[bool]$Strict) {
$local:possibleValues = $(
dco -ProjectPath $Path config --services
)
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
return [DockerComposeServices]::_GetValidValues($wordToComplete,'.',$true)
}
[String[]] GetValidValues() {
return [DockerComposeServices]::_GetValidValues('',$true)
}
}
$null = [DockerComposeCommands]::_GetValidValues("","",$true)
$global:_DockerComposeCompleter = [ScriptBlock]{
param(
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters,
$subCommand
)
$local:cmd = $subCommand
if( -not $cmd ) {
$cmd = $commandAst.CommandElements |
Where-Object Value -in ([DockerComposeCommands]::cachedCommands) |
Select-Object -First 1
}
$local:ProjectPath = $fakeBoundParameters.ProjectPath
if( -not $ProjectPath ) { $ProjectPath=@($PWD) }
if( -not $cmd -or $wordToComplete -match '^-' ) {
[DockerComposeCommands]::_GetValidValues($wordToComplete,$cmd,$true)
} else {
switch($cmd){
'down' {}
'images' {}
'config' {}
default {
[DockerComposeServices]::_GetValidValues($wordToComplete,$ProjectPath,$true)
}
}
}
}
class DockerComposeDirs { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[string]$Path,[bool]$Strict) {
$local:possibleValues = $(
Get-ChildItem -LiteralPath $Path -Directory -Depth 3 |
Where-Object { $_ |
Get-ChildItem -Include 'docker-compose.y*l' |
Where-Object Extension -in '.yml','.yaml'
} | ForEach-Object {
$_.FullName.Replace($(Join-Path $PWD ""),'')
}
)
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
return [DockerComposeDirs]::_GetValidValues($wordToComplete,'.',$true)
}
[String[]] GetValidValues() {
return [DockerComposeDirs]::_GetValidValues('',$true)
}
}
$global:_DockerComposeDirsCompleter = [ScriptBlock]{
param(
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
}