You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(foreach): Remove shell invocation from foreach (#136)
* Remove shell invocation from foreach
As discussed in [issue 135], turbolift applies shell escaping
inconsistently on the arguments in foreach. Upon consideration, I think
there is no good reason to apply shell escaping at all. It makes
turbolift more fragile, more confusing and ultimately less flexible.
Instead, do not use a shell at all and all these problems disappear.
None of the examples in the README use this functionality. If users do
need to invoke a shell, for example to do redirection, it is much more
explicit and understandable for them if they do it themselves.
This PR:
* Removes the use of a shell, instead directly executing a subprocess
based on the arguments provided.
* Removes custom handling of arguments. Users are directed to the
standard GNU-style `--` to indicate that everything else on the
command-line is an argument, not an option. This makes the code
substantially simpler.
[issue 135]: #135
* Format foreach shell arguments nicely
Shell escape the arguments so you can tell when arguments have spaces in
them.
* Require -- before foreach command
Since we are deliberately removing custom handling of arguments, users
will find that if they don't include a double hypen (`--`) separator
before their foreach command, any options they pass to their command
will be interpreted by turbolift and either result in errors, or worse,
being quietly omitted from their command (e.g. `-v`), which could be
surprising and frustrating!
To head this off, refuse immediately if `--` either doesn't appear on
the command-line, or appears after one or more arguments.
* Reword foreach usage for accuracy
Make it clear that the double-hyphen separator `--` is mandatory and not
just a good idea.
* Wrap long usage message
Turns out Cobra doesn't wrap usage messages, so they look pretty ugly if
we don't pick a pretty conservative width and wrap by hand.
* Fix [flags] appearing at end of usage
Turns out Cobra searches your usage line for the specific text "[flags]"
and if it doesn't find it, shoves it on the end. Gross. For that reason,
let's remove explicit callout of any flags and move it back to *before*
the double-hyphen.
* Improve logged command format and add tests
Wrap braces around the logged command to delimit it clearly. Add unit
tests to cover argument formatting.
* Add foreach absolute path example
---------
Co-authored-by: Daniel Ranson <[email protected]>
0 commit comments