yq
yq copied to clipboard
Add Powershell and CMD wrappers
There are issues with escaping evaluation strings on Windows. see #747 #777 et al.
Add a yq.ps1
file
Param(
[string]$command,
[string]$yamlFile
)
$escCommand = $command -replace '"','\"'
$evalArgs = @("eval", "$escCommand", $yamlFile)
Write-Output ".\yq.exe" $evalArgs
& ".\yq.exe" $evalArgs
alternatives
Update the documentation to show how to escape/replace '"' with '"'.
yq e -n '.someNew="content"'.replace('"','\"' )
yq e -n '{"wrap": .}' .replace('"','\"' ) name.yaml
I have not looked into what a similar *.bat or *.cmd file might look like.
The approaches mentioned above may be useful in correcting the documentation found here. https://mikefarah.gitbook.io/yq/usage/tips-and-tricks#quotes-in-windows-powershell
Cool - thanks for this @phreed - if the ps1 file is added, then what should the instructions be for running yq
in Powershell?
I did not write it to be a complete wrapper (the eval command is assumed) but other than that it is pretty much what you might expect. e.g.
yq.ps1 <filter> sample.yaml
yq.ps1 '.someNew="content"' sample.yaml
The filter needs to be enclosed in single quotes to protect any double quotes. I can rework the ps1 script to if you like to make it use all the yq commands, etc. As currently written yq.ps1 assumes the yq.exe is located in the current working directory. It should probably be located in the same directory as the yq.ps1 (not a big problem to correct). I personally despise *.cmd files but you could probably find someone willing to convert a powershell script.
Cool - happy to take your direction, I'm not a powershell user so I'm at a bit of a loss with these things.
Any luck with a PR for this?
I got most of it working and then took a holiday. I have to get some things done for my day job and then I will get back to this.
On Thu, Jun 24, 2021 at 10:21 PM Mike Farah @.***> wrote:
Any luck with a PR for this?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mikefarah/yq/issues/841#issuecomment-868173754, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABTVPGMFD5HOQ2F4B5IQKLTUPY5LANCNFSM45XRQHYQ .
I'm using yq in powershell and would be happy to see it work without workaround!