Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

powershell: register with list #1053

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions example/cmd/_test/powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ Function _example_completer {

$completions
}
Register-ArgumentCompleter -Native -CommandName 'example' -ScriptBlock (Get-Item "Function:_example_completer").ScriptBlock
# Register-ArgumentCompleter -Native -CommandName 'example.exe' -ScriptBlock (Get-Item "Function:_example_completer").ScriptBlock
Register-ArgumentCompleter -Native -ScriptBlock (Get-Item "Function:_example_completer").ScriptBlock -CommandName 'example' # ,'example.exe'

6 changes: 2 additions & 4 deletions internal/shell/powershell/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ Function _%v_completer {

$completions
}
Register-ArgumentCompleter -Native -CommandName '%v' -ScriptBlock (Get-Item "Function:_%v_completer").ScriptBlock
%vRegister-ArgumentCompleter -Native -CommandName '%v.exe' -ScriptBlock (Get-Item "Function:_%v_completer").ScriptBlock
Register-ArgumentCompleter -Native -ScriptBlock (Get-Item "Function:_%v_completer").ScriptBlock -CommandName '%v'%v,'%v.exe'
`

// Snippet creates the powershell completion script.
func Snippet(cmd *cobra.Command) string {
prefix := "# "
prefix := " # "
if runtime.GOOS == "windows" {
prefix = ""
}
Expand All @@ -71,6 +70,5 @@ func Snippet(cmd *cobra.Command) string {
cmd.Name(),
cmd.Name(),
prefix,
cmd.Name(),
cmd.Name())
}