fix: fix PowerShell completion argument parsing #285
ci.yml
on: pull_request
Lint and Type Check
21s
Benchmarks
19s
Matrix: Tests
Annotations
6 errors
|
Tests (macos-latest)
Process completed with exit code 1.
|
|
tests/shell.test.ts > shell completion generators > powershell completion > should generate a valid powershell completion script:
tests/shell.test.ts#L165
AssertionError: expected '# powershell completion for testcli -…' to contain '$RequestComp = "& /usr/bin/node /path…'
- Expected
+ Received
- $RequestComp = "& /usr/bin/node /path/to/testcli complete --
+ # powershell completion for testcli -*- shell-script -*-
+
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
+ function __testcli_debug {
+ if ($env:BASH_COMP_DEBUG_FILE) {
+ "$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
+ }
+ }
+
+ filter __testcli_escapeStringWithSpecialChars {
+ $_ -replace '\s|#|@|\$|;|,|''|\{|\}|\(|\)|"|\||<|>|&','`$&'
+ }
+
+ [scriptblock]$__testcliCompleterBlock = {
+ param(
+ $WordToComplete,
+ $CommandAst,
+ $CursorPosition
+ )
+
+ # Get the current command line and convert into a string
+ $Command = $CommandAst.CommandElements
+ $Command = "$Command"
+
+ __testcli_debug ""
+ __testcli_debug "========= starting completion logic =========="
+ __testcli_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
+
+ # The user could have moved the cursor backwards on the command-line.
+ # We need to trigger completion from the $CursorPosition location, so we need
+ # to truncate the command-line ($Command) up to the $CursorPosition location.
+ # Make sure the $Command is longer then the $CursorPosition before we truncate.
+ # This happens because the $Command does not include the last space.
+ if ($Command.Length -gt $CursorPosition) {
+ $Command = $Command.Substring(0, $CursorPosition)
+ }
+ __testcli_debug "Truncated command: $Command"
+
+ $ShellCompDirectiveError=1
+ $ShellCompDirectiveNoSpace=2
+ $ShellCompDirectiveNoFileComp=4
+ $ShellCompDirectiveFilterFileExt=8
+ $ShellCompDirectiveFilterDirs=16
+ $ShellCompDirectiveKeepOrder=32
+
+ # Prepare the command to request completions for the program.
+ # Split the command at the first space to separate the program and arguments.
+ $Program, $Arguments = $Command.Split(" ", 2)
+
+ $RequestComp = "& /usr/bin/node /path/to/testcli complete '--' $Arguments"
+ __testcli_debug "RequestComp: $RequestComp"
+
+ # we cannot use $WordToComplete because it
+ # has the wrong values if the cursor was moved
+ # so use the last argument
+ if ($WordToComplete -ne "" ) {
+ $WordToComplete = $Arguments.Split(" ")[-1]
+ }
+ __testcli_debug "New WordToComplete: $WordToComplete"
+
+
+ # Check for flag with equal sign
+ $IsEqualFlag = ($WordToComplete -Like "--*=*" )
+ if ( $IsEqualFlag ) {
+ __testcli_debug "Completing equal sign flag"
+ # Remove the flag part
+ $Flag, $WordToComplete = $WordToComplete.Split("=", 2)
+ }
+
+ if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
+ # If the last parameter is complete (there is a space following it)
+ # We add an extra empty parameter so we can indicate this to the go method.
+ __testcli_debug "Adding extra empty parameter"
+ # PowerShell 7.2+ changed the way how the arguments are passed to executables,
+ # so for pre-7.2 or when Legacy argument passing is enabled we need to use
+ if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
+ ($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or
+ (($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and
+ $PSNativeCommandArgumentPassing -eq 'Legacy')) {
+ $RequestComp="$RequestComp" + ' `"`"'
+ } else {
+ $RequestComp = "$RequestComp" + ' ""'
+ }
+ }
+
+ __testcli_debug "Calling $RequestComp"
+ # First disable ActiveHelp which is not supported for Powershell
+ $env:ActiveHelp = 0
+
+ # call the command store the output in $out and redirect std
|
|
Tests (windows-latest)
The strategy configuration was canceled because "test.macos-latest" failed
|
|
Tests (windows-latest)
The operation was canceled.
|
|
Tests (ubuntu-latest)
The strategy configuration was canceled because "test.macos-latest" failed
|
|
Tests (ubuntu-latest)
The operation was canceled.
|