PowerShell completion scripts (Effect's internal
completions/powershell): the command tree as data and one native
argument completer reading it.
Values#
| Attribute | Type | Description |
|---|---|---|
COMPLETER | str | The completer's body, as Effect writes it, reading the data at |
Functions#
generate#
generate(executable, descriptor) -> str| Parameter | Type | Description |
|---|---|---|
executable | str | |
descriptor | CommandDescriptor |
Returns str
def generate(executable: str, descriptor: CommandDescriptor) -> str:
data = f"$global:_{_sanitize(executable)}_Completions"
lines = [
f"###-begin-{executable}-completions-###",
"#",
"# Static completion script for PowerShell",
"#",
"# Installation:",
f"# {executable} --completions powershell > {executable}-completion.ps1",
"# then add this line to your $PROFILE (use the full path to the file):",
f"# . <PATH>\\{executable}-completion.ps1",
"#",
"",
f"{data} = [hashtable]::new([System.StringComparer]::Ordinal)",
]
_contexts(data, descriptor, [], lines, set())
lines.append("")
lines.append(
f"Register-ArgumentCompleter -Native -CommandName {_quote(executable)} -ScriptBlock {{"
)
lines.append(COMPLETER.replace(_DATA_NAME, data))
lines.append("}")
lines.append("")
lines.append(f"###-end-{executable}-completions-###")
return "\n".join(lines)