-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerate-AutocompleteScript.ps1
More file actions
44 lines (30 loc) · 1.05 KB
/
Generate-AutocompleteScript.ps1
File metadata and controls
44 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$config = "gxcli.config"
if (-not (Test-Path $config)){
Write-Host Config file was not found
return
}
$json = Get-Content $config | ConvertFrom-Json
$verbs = @()
$def = "`t`tdefault {`"help`","
$json.Providers | Get-Member -MemberType NoteProperty | ForEach-Object {
$key = $_.Name
$verb = [PSCustomObject]@{Name = $key; Parameters = $json.Providers."$key".Parameters}
$line = "`t`t'" + $verb.Name + "' {`"help`","
$def += "`"" + $verb.Name + "`","
$verb.Parameters | ForEach-Object {
$p = $_.Name
$param = [PSCustomObject]@{Name = $p }
$line += "`"" + $param.Name + "`"" + ","
}
$line = $line.Substring(0, $line.Length -1)
$line += ";break }`r`n"
$verbs += $line
}
$def = $def.Substring(0,$def.Length - 1)
$def += "}"
$template = Get-Content gxcli-autocomplete.template -Raw
$template = $template.Replace("{{VERBS}}",$verbs)
$template = $template.Replace("{{DEFAULT}}",$def)
$outputPath = "gxcli-autocomplete.ps1"
Set-Content $outputPath $template
Invoke-Expression -Command $outputPath