Skip to content

Conversation

@DannyBen
Copy link
Member

@DannyBen DannyBen commented Oct 10, 2021

This PR supersedes (and includes) #114.

Changes on top of the original:

  • Bash 3 bouncer is now in its separate partial (but is still considered a "header", in case it is replaced by the user).
  • Bash 3 bouncer will only be included when a standalone script is generated. When a function is generated, it is left to the user to take care of it some other way.
  • Some high churn specs were modified to use approvals instead of exact text matches

wolfgang42 and others added 6 commits October 8, 2021 10:15
This test fails with:

    /app/cli: line 117: conditional binary operator expected
    /app/cli: line 117: syntax error near `missingno'
    /app/cli: line 117: `  if [[ -v missingno ]]; then'
Bash executes the script as it's reading it. When it encounters a function,
it parses the function body before continuing. The bashly-generated script
has *all* of its code in functions which appear before any code is executed
(the initialize/run functions are only called at the bottom of the script).
Normally this is useful, since it ensures that bash has loaded/parsed the
whole script before beginning execution; however, in the case of this
version check it means that if any of the functions contain syntax that
Bash 3 doesn't understand, it will choke on that and crash (with a much
less helpful error) before it has a chance to execute the version check.

This commit moves that check to the very top of the file, where it will be
executed and trigger an early exit before bash tries to parse the rest of
the script, so that it will work correctly regardless of the remainder of
the contents.
@DannyBen
Copy link
Member Author

@wolfgang42 - this is mostly your PR, with some flavor.

I will leave it here to cool off for a day or two, to give you a chance to take a look if you want, and will merge afterwards.

@wolfgang42
Copy link
Collaborator

Looks reasonable to me. I assume the intent is that scripts using the wrap feature will implement the check if necessary in the sourcing script, and for standalone use they just won't have this check unless they implement a custom header?

@DannyBen
Copy link
Member Author

Well - when someone generates a function, I am assuming they intend to source it and use it as part of a larger script, placing any code outside that function "breaks the contract" between us.

@wolfgang42
Copy link
Collaborator

But there is code outside the function, specifically this line:

https://github.com/DannyBen/bashly/blob/d8a9e2e1e165fe85fa74776becc4fe57006f057c/lib/bashly/views/script/wrapper.erb#L6

which makes it possible to also run the wrapped script standalone. But the way you've implemented it, using --wrap will cause the script to lose the bash version check even when it's used as a regular script instead of being sourced. (Which seems reasonable given the constraints you've outlined, I just thought it was important to call out as a caveat.)

@DannyBen DannyBen merged commit fa8db80 into master Oct 12, 2021
@DannyBen DannyBen deleted the finalize/pr-114 branch October 12, 2021 06:03
@DannyBen
Copy link
Member Author

version 0.6.8 is out with the recent changes. I will update the docs.
as for the remaining open PR, I will play with it more before considering how to proceed.

Thanks @wolfgang42

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