Support backslash line continuation in crontabs - #246
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
A crontab entry can now span several physical lines by ending a line with a backslash, the same way a shell continues a line. The parser joins those lines back together before parsing the schedule and command. Closes aptible#104
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #104.
This adds support for splitting a long crontab entry across several lines by ending a line with a backslash, like you can in a shell. The parser joins the continued lines back together before it works out the schedule and command, so this:
now parses as a single job instead of being rejected.
A trailing backslash that is itself escaped (an even number of backslashes) does not continue the line, and the join happens after the comment check so a comment ending in a backslash can't swallow the job on the next line. I added test cases for the basic case, several continuations in a row, an env definition, the escaped-backslash case, and the comment guard, plus a short note in the README.
Happy to adjust the join behavior (for example trimming the leading whitespace on continued lines) if you would prefer something different.