-
-
Notifications
You must be signed in to change notification settings - Fork 617
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: Wrap example does not work #747
Comments
Have you seen this: https://mikefarah.gitbook.io/yq/usage/tips-and-tricks#quotes-in-windows-powershell ? |
As I said: yes. |
Oh right sorry - no idea then, I got that advice from here https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.1 for what it's worth - perhaps there's doc for whatever version of powershell you are using.. |
The work around is to quote in the following way. .\yq.exe e '{\"wrap\": .}' sample.yaml You can see that this is strictly a Powershell issue by the following example. echoargs e '{\"wrap\": .}' sample.yaml
|
Here is a Param(
[string]$command,
[string]$yamlFile
)
$escCommand = $command -replace '"','\"' -replace ' ',''
$evalArgs = @("eval", $escCommand, $yamlFile)
Write-Output ".\yq.exe" $evalArgs
Start-Process ".\yq.exe" -ArgumentList $evalArgs -Wait -NoNewWindow -PassThru I am not sure about the removing whitespace bit. But, without it |
Here is a Param(
[string]$command,
[string]$yamlFile
)
$escCommand = $command -replace '"','\"'
$evalArgs = @("eval", "$escCommand", $yamlFile)
Write-Output ".\yq.exe" $evalArgs
& ".\yq.exe" $evalArgs |
Thanks for the pointer on Here's the one thing that confuses me, though: At least in PowerShell 6 (7 doesn't work under remote sessions), the "Arg..." output of PS C:\Users\***> yq -M '{""wrap"": .}' sample.yml
Error: parsing expression: Lexer error: could not match text starting at 1:2 failing at 1:7.
unmatched text: "\"wrap:"
PS C:\Users\***> echoargs e '{""wrap"": .}' sample.yml
Arg 0 is <e>
Arg 1 is <{"wrap": .}>
Arg 2 is <sample.yml>
Command line:
"C:\ProgramData\chocolatey\lib\echoargs\tools\EchoArgs.exe" e "{""wrap"": .}" sample.yml
PS C:\Users\***> yq -M e '{\"wrap\": .}' sample.yml
wrap:
name: Mike
PS C:\Users\***> echoargs e '{\"wrap\": .}' sample.yml
Arg 0 is <e>
Arg 1 is <{"wrap": .}>
Arg 2 is <sample.yml>
Command line:
"C:\ProgramData\chocolatey\lib\echoargs\tools\EchoArgs.exe" e "{\"wrap\": .}" sample.yml In fact, another working form — as I just discovered — is this: PS C:\Users\***> yq -M e "{\""wrap\"": .}" sample.yml
wrap:
name: Mike It doesn't work without the backslashes, and interestingly, PS C:\Users\***> echoargs e "{""wrap"": .}" sample.yml
Arg 0 is <e>
Arg 1 is <{wrap: .}>
Arg 2 is <sample.yml>
Command line:
"C:\ProgramData\chocolatey\lib\echoargs\tools\EchoArgs.exe" e "{"wrap": .}" sample.yml
PS C:\Users\***> echoargs e "{\""wrap\"": .}" sample.yml
Arg 0 is <e>
Arg 1 is <{"wrap": .}>
Arg 2 is <sample.yml>
Command line:
"C:\ProgramData\chocolatey\lib\echoargs\tools\EchoArgs.exe" e "{\"wrap\": .}" sample.yml (Notice how, without the backslashes, |
If you want the old behavior you can use |
But yq does some really weird stuff when using
prints
So yq gets the correct parameters but for some reason thinks |
I believe yq is getting the literal string
|
Describe the bug
I tried running the sample from https://mikefarah.gitbook.io/yq/v/v4.x/operators/create-collect-into-object#wrap-prefix-existing-object in PowerShell but I can't seem to get it to work.
Version of yq: 4.6.1
Operating system: windows
Installed via: binary release
Input Yaml
Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less)
sample.yml:
Command
The command you ran:
Actual behavior
Expected behavior
Additional context
I tried both the original code snippet with single ", but then found out that I apparently have to double the quotes in PowerShell, but that didn't not help either :(.
The text was updated successfully, but these errors were encountered: