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

"ignore-comments" does not completely ignore commented lines #2339

Closed
eddyg opened this issue Sep 2, 2024 · 6 comments
Closed

"ignore-comments" does not completely ignore commented lines #2339

eddyg opened this issue Sep 2, 2024 · 6 comments

Comments

@eddyg
Copy link

eddyg commented Sep 2, 2024

Because both Docker and just use Go-style templates, it is necessary to escape any occurrences of {{ to {{{{ in various recipes that need to use Docker's --format option.

I put a comment in the recipe with the same command without escaping the {{, with the intention of being able to easily copy the command from the justfile and paste it (in a "ready-to-go" state) in to an arbitrary shell for debugging, systems without just, etc.

For example:

set ignore-comments

ls-mounts:
    # docker inspect --format '{{range .Mounts}}{{if .Name}}{{.Name}}{{else}}{{.Source}}{{end}}{{"\n"}}{{end}}' $(docker ps --all --quiet) | grep -v '^$' | sort -u
    docker inspect --format '{{{{range .Mounts}}{{{{if .Name}}{{{{.Name}}{{{{else}}{{{{.Source}}{{{{end}}{{{{"\n"}}{{{{end}}' $(docker ps --all --quiet) | grep -v '^$' | sort -u

However, the {{ in the commented line causes just to fail — I have to escape them even though they are in the comment, which defeats my intended purpose.

Any suggestions?

P.S. Thanks for just!

@casey
Copy link
Owner

casey commented Sep 2, 2024

Thanks for the issue! This is definitely annoying, but it would be pretty hard to solve, and might not be worth the complexity. Whether or not ignore-comments is turned on can only be determined after parsing, so the justfile must be parsable, which includes comments, and unmatched {{ and invalid syntax in {{…}} are both parse errors. So ignore-comments is only able to ignore errors that happen after parsing, like unknown variables.

I'll leave this open. A solution might be to defer parsing recipe bodies, but I honestly think the code for that might be so ugly that it won't be worth it.

@eddyg
Copy link
Author

eddyg commented Sep 2, 2024

Thanks for the explanation! I totally understand why this happens now. 🙂

Would it be possible to have an option to print a recipe "as it it would be executed"?

That might actually be better, because then it doesn't mean maintaining a copy of the command in a comment.

For example, just --print ls-mounts could print the "unescaped" commands in the recipe (perhaps optionally along with any comments), ready for copy-and-pasting?

@laniakea64
Copy link
Contributor

See also #2179

Would it be possible to have an option to print a recipe "as it it would be executed"?

That might actually be better,

just --dry-run ls-mounts

@casey
Copy link
Owner

casey commented Sep 2, 2024

Yah, i think just --dry-run might be what you want, give that a shot.

@eddyg
Copy link
Author

eddyg commented Sep 2, 2024

Ah! I don't know how I missed --dry-run. 🤦‍♂️

I do indeed think that will be an OK work-around given the previously-explained difficulties of trying to completely ignore comments.

Thanks for the super-quick responses! (I'll leave it up to you if you want to keep this issue open, but completely understand if you want to consider it a "won't fix".)

@casey
Copy link
Owner

casey commented Sep 2, 2024

Nice, glad that works! I think I'm going to close this. It would be nice to fix it, but the fix would be to delay parsing recipe bodies and store them in an unparsed form, and then parse them later on, which would be super gross.

@casey casey closed this as completed Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants