Skip to content

Commit a878aed

Browse files
committed
Split terraform and docker profiles.
1 parent bb06eca commit a878aed

3 files changed

+83
-55
lines changed
+50-50
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
# 1.0.8007.19673
1+
# 1.0.8030.25528
22

33
[CmdletBinding()]
44
param( [switch]$completions )
55

6-
"C:\Portable Apps\Terraform", `
76
"C:\Portable Apps\Helm" `
8-
| Add-DirectoryToPath
7+
| Add-DirectoryToPath
98

109
if ($completions.IsPresent) {
1110

1211
Write-Host "Loading CLI completions for docker | helm | kubectl." -ForegroundColor Cyan
1312

14-
## CLI completions require Git bash
15-
16-
$__GIT_HOME=Join-Path -Path (Split-Path (Split-Path -Path (Get-Command "git").Source)) -ChildPath "bin"
17-
$__GIT_HOME | Add-DirectoryToPath -Prepend
18-
1913
Function Has-Module {
2014
param([string]$name)
2115
return [bool] (Get-Module -ListAvailable -Name $name)
2216
}
2317

18+
## This function is taken from
19+
## https://github.com/springcomp/powershell_profile.ps1/blob/bb06eca65fda4d62c12269c8f770c562f8533c6c/Pwsh-Profile/Load-Profile.psm1#L14-L25
20+
##
21+
## TODO: allow module to run scripts in global scope instead of copying this function
22+
Function Get-PwshExpression {
23+
param([string]$path)
24+
25+
## Using [IO.File]::ReadAllText() instead of Get-Content -Raw for performance purposes
26+
27+
$content = [IO.File]::ReadAllText($path)
28+
$content = $content -replace "(?<!\-)[Ff]unction\ +([_A-Za-z]+)", 'Function global:$1'
29+
$content = $content -replace "(?<!\-)[Ff]ilter\ +([_A-Za-z]+)", 'Filter global:$1'
30+
$content = $content -replace "[Ss][Ee][Tt]\-[Aa][Ll][Ii][Aa][Ss]\ +(.*)", 'Set-Alias -Scope Global $1'
31+
32+
Write-Output $content
33+
}
34+
Function Install-DockerCompletion {
35+
Install-Module DockerCompletion -Scope CurrentUser -Force
36+
}
2437
Function Install-KubeCompletion {
2538
[CmdletBinding()]
2639
param([Alias("CompletionsPath")][string]$path)
27-
Install-Module DockerCompletion -Scope CurrentUser -Force
28-
Install-Module -Name PSBashCompletions -Scope CurrentUser -Force
40+
41+
## kubectl completion for PowerShell required v1.23.x
42+
$version = ConvertFrom-JSON -InputObject (kubectl version).Replace("Client Version: version.Info", "")
43+
if ($version.Minor -lt 23) {
44+
Write-Host "kubectl CLI completion requires v1.23.0 or later. Please, upgrade kubectl.exe." -ForegroundColor Red
45+
Write-Host "Please, refer to the following instructions to install kubectl:" -ForegroundColor Yellow
46+
Write-Host " https://kubernetes.io/docs/tasks/tools/install-kubectl-windows" -ForegroundColor DarkGray
47+
return
48+
}
49+
2950
New-Item -Path $path -ItemType Directory -EA SilentlyContinue | Out-Null
30-
((kubectl completion bash) -join "`n") | Set-Content -Encoding ASCII -NoNewline -Path $path/kubectl.sh
31-
((helm completion bash) -join "`n") | Set-Content -Encoding ASCII -NoNewline -Path $path/helm.sh
51+
kubectl completion powershell | Out-String | Set-Content -Encoding ASCII -NoNewline -Path $path/kubectl.ps1
52+
}
53+
Function Install-HelmCompletion {
54+
[CmdletBinding()]
55+
param([Alias("CompletionsPath")][string]$path)
56+
New-Item -Path $path -ItemType Directory -EA SilentlyContinue | Out-Null
57+
helm completion powershell | Out-String | Set-Content -Encoding ASCII -NoNewline -Path $path/helm.ps1
3258
}
3359

3460
$completionsPath = Join-Path (Split-Path -Parent $PROFILE) Completions
35-
if ( (-not (Has-Module DockerCompletion)) `
36-
-or (-not (Has-Module PSBashCompletions)) `
37-
-or (-not (Test-Path $completionsPath/kubectl.sh)) `
38-
-or (-not (Test-Path $completionsPath/helm.sh))
39-
) {
61+
if (-not (Has-Module DockerCompletion)) { Install-DockerCompletion }
62+
if (-not (Test-Path $completionsPath/helm.ps1)) {
63+
Install-HelmCompletion -Completions $completionsPath
64+
}
65+
if (-not (Test-Path $completionsPath/kubectl.ps1)) {
4066
Install-KubeCompletion -Completions $completionsPath
4167
}
4268

4369
Import-Module DockerCompletion
4470

45-
if (Test-Path $completionsPath) {
46-
Import-Module PSBashCompletions
47-
Register-BashArgumentCompleter kubectl "$completionsPath/kubectl.sh"
48-
Register-BashArgumentCompleter kc "$completionsPath/kubectl.sh"
49-
Register-BashArgumentCompleter helm "$completionsPath/helm.sh"
71+
if (Test-Path $completionsPath/helm.ps1) {
72+
Get-PwshExpression -Path "$completionsPath/helm.ps1" | Invoke-Expression
73+
}
74+
if (Test-Path $completionsPath/kubectl.ps1) {
75+
Get-PwshExpression -Path "$completionsPath/kubectl.ps1" | Invoke-Expression
5076
}
5177
}
5278

5379
Function compose { docker compose $args }
5480

55-
Function tf-init {
56-
terraform init `
57-
-backend-config $PWD\tfbackend.tfvars
58-
$args
59-
}
60-
Function tf-plan {
61-
$varFile = Get-ChildItem -Path $PWD -Filter *.tfvars |? { $_.Name -ne "tfbackend.tfvars" }
62-
terraform plan `
63-
-var-file "$PWD\$($varfile.Name)" `
64-
-var validate_datadog=false `
65-
$args
66-
}
67-
Function tf-apply {
68-
$varFile = Get-ChildItem -Path $PWD -Filter *.tfvars |? { $_.Name -ne "tfbackend.tfvars" }
69-
terraform apply `
70-
-var-file "$PWD\$($varfile.Name)" `
71-
-var validate_datadog=false `
72-
-auto-approve `
73-
$args
74-
}
75-
76-
Function tf-import {
77-
$varFile = Get-ChildItem -Path $PWD -Filter *.tfvars |? { $_.Name -ne "tfbackend.tfvars" }
78-
terraform import `
79-
-var-file "$PWD\$($varfile.Name)" `
80-
-var validate_datadog=false `
81-
$args
82-
}
81+
Set-Alias -Name "kube" -Value kubectl
82+
Set-Alias -Name "kc" -Value kubectl
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 1.0.8007.19673
2+
3+
"C:\Portable Apps\Terraform" `
4+
| Add-DirectoryToPath
5+
6+
Function tf-init {
7+
terraform init `
8+
-backend-config $PWD\tfbackend.tfvars
9+
$args
10+
}
11+
Function tf-plan {
12+
$varFile = Get-ChildItem -Path $PWD -Filter *.tfvars |? { $_.Name -ne "tfbackend.tfvars" }
13+
terraform plan `
14+
-var-file "$PWD\$($varfile.Name)" `
15+
-var validate_datadog=false `
16+
$args
17+
}
18+
Function tf-apply {
19+
$varFile = Get-ChildItem -Path $PWD -Filter *.tfvars |? { $_.Name -ne "tfbackend.tfvars" }
20+
terraform apply `
21+
-var-file "$PWD\$($varfile.Name)" `
22+
-var validate_datadog=false `
23+
-auto-approve `
24+
$args
25+
}
26+
27+
Function tf-import {
28+
$varFile = Get-ChildItem -Path $PWD -Filter *.tfvars |? { $_.Name -ne "tfbackend.tfvars" }
29+
terraform import `
30+
-var-file "$PWD\$($varfile.Name)" `
31+
-var validate_datadog=false `
32+
$args
33+
}

Properties.xml

-5
This file was deleted.

0 commit comments

Comments
 (0)