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

Fix handling comments in multiline cmds #225

Merged

Conversation

snejus
Copy link
Contributor

@snejus snejus commented Jun 15, 2024

Fixes #224

@snejus snejus force-pushed the fix-handling-comments-in-multiline-cmds branch from 54b2aea to f267c87 Compare June 19, 2024 14:21
@snejus
Copy link
Contributor Author

snejus commented Jun 19, 2024

Now regarding the test case with multiple comments - it actually evaluates to an invalid command if it's read literally (a comment between two flags does not make any sense).

Do you see any value in supporting this kind of thing? We could potentially pre-parse the command and ignore all comments altogether.

kianmeng and others added 3 commits June 24, 2024 00:51
Found via `typos --hidden --format brief` and `codespell -H -L cant`
…-n#229)

Fixes nat-n#203

Also:
- Adds GitRepo abstraction in helpers for calling git
- Make EnvVarsManager implement Mapping so it can be passed directly to `apply_envvars_to_template`
- Update poetry.lock
To do with we now track how a line in cmd conent was terminated on the
ast.Line class so that lines terminated by a comment can be implicitly merged.
@nat-n
Copy link
Owner

nat-n commented Jun 23, 2024

Now regarding the test case with multiple comments - it actually evaluates to an invalid command if it's read literally (a comment between two flags does not make any sense).

Do you see any value in supporting this kind of thing? We could potentially pre-parse the command and ignore all comments altogether.

Your assessment is correct. Allowing a cmd to be split over multiple lines (with escaping the line break) with comments on multiple lines is a little bit weird... but harmless and IMO potentially a nice thing to be able to do.

I think the root cause of the issue here is that although I made the AST implementation faithful to a subset of bash, when actually used in the cmd task it's configured to only treat ; as a line terminator (not line breaks) and to later ignore lines with only whitespace or comments. However comments at the end of lines still end up terminating that line.

So to resolve this I just pushed a tweak to the cmd AST that allows tracking on the Line object how it was terminated, so that we can implicitly merge lines that were only terminated with a comment. WDYT?

@nat-n nat-n changed the base branch from main to development June 23, 2024 22:52
@nat-n nat-n marked this pull request as ready for review June 24, 2024 19:28
@nat-n
Copy link
Owner

nat-n commented Jun 24, 2024

This looks good to me now. Thanks for working on it @snejus

@nat-n nat-n merged commit f863aa8 into nat-n:development Jun 24, 2024
19 checks passed
@snejus snejus deleted the fix-handling-comments-in-multiline-cmds branch June 26, 2024 22:09
@snejus
Copy link
Contributor Author

snejus commented Jun 26, 2024

Amazing, thanks for finishing this up!

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

Successfully merging this pull request may close these issues.

3 participants