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

gomplate v3.9.0 > "unknown command \"{{\" for \"gomplate\""[0m" on windows #1095

Closed
adriens opened this issue Mar 23, 2021 · 6 comments
Closed
Assignees
Labels

Comments

@adriens
Copy link
Contributor

adriens commented Mar 23, 2021

Context

While running gomplate version 3.9.0 on windows and trying the run the person.json datasource tutorial I'm not able to properly run the scenario.

Please notice I've used the gomplate_windows-amd64.exe binary.

But when I run the following command :

gomplate -d person=./person.json -i 'Hello {{ (datasource "person").name }}'

I get the following output (looking like something's wrong with the encoding) :

�[90m11:00:16�[0m �[1m�[31mERR�[0m�[0m  �[31merror=�[0m�[31m"unknown command \"{{\" for \"gomplate\""�[0m

... while everything runs normally on my local vagrant, on the same machine (through brew install) :

vagrant@vagrant:~$ gomplate -d person.json -i 'Hello {{ (datasource "person").name }}'
Hello Dave

I can't figure out what's going wrong or if I used the bad binary ?... should I rather use gomplate_windows-amd64-slim.exe ?

Thank you in advance for your help. Your tools looks perfectly cool to achieve the goals I have.

Kind regards,
Adrien

@adriens
Copy link
Contributor Author

adriens commented Mar 23, 2021

#527

@hairyhenderson
Copy link
Owner

Hi @adriens, thanks for logging this, and sorry for the delay - it's been a busy week!

I'll start with the last question since that's simplest 😉

I can't figure out what's going wrong or if I used the bad binary ?... should I rather use gomplate_windows-amd64-slim.exe ?

Keep using the non-slim.exe binary. The slim binary is a self-decompressing executable - the idea being that it's smaller to download, but takes more CPU to execute. In practice however this hasn't turned out very well - the tool that I use to compress it (UPX) has been quite flaky over the past few years, and I'm planning on dropping it entirely soon.

I get the following output (looking like something's wrong with the encoding) :

The encoding clearly isn't working right on a Windows terminal. The logging package that gomplate uses emits ANSI colour-coded messages when it thinks it's in an interactive terminal - there are ways to enable ANSI in the Windows terminal, but it's not default. I think the best fix for now is for gomplate to detect if it's running in Windows and avoid using colours then.

As for the actual issue with the command not working as expected, I'm not a Windows user so I can't be 100% sure, but I think the problem is simply with quoting. The Windows command prompt doesn't treat ' as a quoting character (like "), so that particular example will only work as-is in the PowerShell terminal, or on Linux/macOS shells.

Here are some alternate options to try:

C:\> gomplate -d person=./person.json -i "Hello {{ (datasource `person`).name }}"
C:\> gomplate -d person=./person.json -i "Hello {{ (datasource \"person\").name }}"
C:\> gomplate -d person=./person.json -i "Hello {{ (datasource ^"person^").name }}"

Some explanation:

  • in the first command, the ` character is interpreted by gomplate as a quote character, similar to ". Not sure if cmd.exe will interpret it or pass it through unmodified
  • in the second, \" is an attempt to escape the ", but it's unclear whether cmd.exe understands this or not
  • in the third, ^" is another attempt to escape the " - some quick googling suggests that this might be what cmd.exe will understand natively.

All that being said, when you're using gomplate "for real" it's a bit more customary to pass through an input file (with -f) instead of an input string on the command line, so much less messing around with shell quoting and escaping 😉

@hairyhenderson
Copy link
Owner

hairyhenderson commented Mar 27, 2021

I managed to get access to a Windows VM, and I found that the first two options (` and \") work fine, though ^" doesn't. I'll update the documentation with a sample that's Windows-compatible and then close this issue.

On second thought, the docs are very UNIX-shell centric, so making all the examples compatible with Windows would be an enormous undertaking. Also, there seems to be a number of different terminals in use for Windows now - the legacy cmd.exe, PowerShell, and Windows Terminal. The latter two seem to support ' just fine, so it'd only be relevant for legacy cmd.exe users.

I'm going to leave this as-is, and close this issue. Maybe if someone else runs into this in future, they'll find this issue and recognize that they just need to use appropriate quoting for their shell.

@adriens
Copy link
Contributor Author

adriens commented Apr 1, 2021

Hi, I'm giving a try to two ther terminals :

  • PowerShell
  • Windows Terminal

I'll let you know on this ticket.

@adriens
Copy link
Contributor Author

adriens commented Apr 1, 2021

Powershell is not a great experience, but the cleanest and simplest approach then is to use a real bash under windows.

So I decided to try from Git Bash as most Dev and OPS do have it on their Windows and it works perfeclty well :

image

@adriens
Copy link
Contributor Author

adriens commented Apr 1, 2021

On second thought, the docs are very UNIX-shell centric, so making all the examples compatible with Windows would be an enormous undertaking.

Totally agree 👍

Also, there seems to be a number of different terminals in use for Windows now - the legacy cmd.exe, PowerShell, and Windows Terminal. The latter two seem to support ' just fine, so it'd only be relevant for legacy cmd.exe users.

Yep, would make no sens 👌

I'm going to leave this as-is, and close this issue. Maybe if someone else runs into this in future, they'll find this issue and recognize that they just need to use appropriate quoting for their shell.

💯 I would add if other windows users fall on the same issue, ask them to use a proper shell, and that Git bash perfectly does the job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants