-
Notifications
You must be signed in to change notification settings - Fork 515
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
Deal with list substitution #208
Comments
My main concern is that it feels like it might be a case of getting the wrong result from all of the right parts... possibly for unavoidable reasons.
Despite all that, I have this nagging feeling that it's Bourne shell's biggest footgun, writ more verbose. (In my dash and bash scripts, I end up writing constructs like If it weren't for the backwards compatibility issue, I'd say to make variables like auto-quoted and use the function to opt into unquoted behaviour. |
I agree that it's an ugly solution, but with the Bourne shell's terrible splitting semantics, it feels like it's the best worst option. Auto-quoting variables is interesting, but requiring users to opt-out of quoting feels weird. I guess it would be an Alternatively, we can build a time machine, go back to 1989 and pick up Tom Duff – right after he wrote the rc shell, which has much better splitting and quoting behavior – and then head to 1977 so he can have a chat with Stephen Bourne and we can avoid this whole mess. |
I'd think of it more in terms of Then, you'd get this intuitive-for-anything-but-bash behaviour: (You'd want to split using something like the |
...and I'd argue that, since Heck, I actually found it confusing and UN-intuitive when something which was obviously a pre-processing step separate from the Bourne shell evaluation with syntax inspired by an HTML templating engine which auto-escapes didn't auto-escape in this context. |
Hi there We have more than 50 just tasks currently for various unrelated tasks, so we have split them up to multiple directories to simulate "namespaces". We've got a
So we end up going back to This all works nicely up until we have some script that wants arguments to be passed like |
Hi Vesa! What you're doing is really cool, it would be nice to support subcommands natively. Unfortunately I don't think there's a good way to work around this right now. I don't know of a solution which would work consistently for different use cases and shells. I'm definitely open to suggestions, but I don't have a lot of bandwidth to work on |
Thanks for getting back to me so soon 😊. Issues with quoting are definitely one of the biggest annoyances with shells and difficult to solve. I didn't expect you to have any solution but hey, it was worth a try 😃 Thanks for this tool, it has been really helpful in automating our mundane admin and chore tasks |
Ok, now I think I'm in a happy place. I can write commands like this:
We'll merely have to use both single and double quotes for arguments containing spaces. That's completely reasonable, as there's (as far as I understand) no way for I only need to use this kind of syntax in various places when I'm going deeper in to other tasks. Yes, it's additional glue code and I wish I didn't need to write that, but it will suffice. # in root Justfile
admin +args='help':
#!/usr/bin/env bash
set -eo pipefail
args_as_is=$(cat <<EOF;
{{args}}
EOF)
just --working-directory `pwd` --justfile tasks/admin/Justfile $args_as_is
# in tasks/admin/Justfile
fix-venue-location env='staging' +ARGS='--usage':
#!/usr/bin/env bash
set -eo pipefail
args_as_is=$(cat <<EOF;
{{ARGS}}
EOF)
just admin _run-ruby-script-using-confirmation {{env}} fix_venue_location $args_as_is
_run-ruby-script-using-confirmation env script_name +ARGS:
#!/usr/bin/env bash
set -eo pipefail
args_as_is=$(cat <<EOF;
{{ARGS}}
EOF)
# ...and so on |
It's definitely not ideal, but I'm glad that you were able to find a workaround. I just opened #383, which I hope eventually leads to just natively supporting submodules and subcommands, which I think would be really cool |
My two cents:
|
@kwshi I agree with your thoughts on Ideally, Just would have a static type system, so Also, @valscion, there's a new feature which you might find useful for passing arguments that would otherwise need to be quoted. (@kwshi, thanks for reminding me!) If you add For example:
The shell won't interpret quotes, spaces, or other special characters inside of positional argument values, and will pass them to sub-commands unmmolested. Another thing you can do is add a
I think that this might help with your use cases. |
Cool, thanks for letting me know of these new features! I'll keep them in mind the next time I'm figuring out our Justfile usages |
Currently, a
+
argument is a string consisting of the original arguments separated by spaces.This presents difficulties, since the shell will re-split the text. If the argument contains intra-argument spaces, bad things can happen.
For example, with the following justfile:
Invoking just with:
just compile -DVAR='hello, world'
Will run the command:
cc -DVAR=hello, world
Since the single quotes were evaluated in the calling shell, the command line will be parsed by the subshell invoked by just as
cc
,-DVAR=hello,
, andworld
, which is clearly not what was intended.So, given this problem, here's what I'm thinking of for a solution:
I'll add functions, with the first one being a
quote()
function. Quote may be applied to any variable, like so:quote(variable)
. In a recipe, one would use it like this:It will surround each element of a list with quotes, escaping existing quotes and backslashes as necessary.
I haven't decided on whether to use quotes or double quotes. I think it mostly depends on which has the most consistent behavior between
dash
andbash
.This complicates the type system a little bit, since we now must distinguish between lists and strings. I propose that all variables are now lists of strings, and so existing variables are now single-element lists. So, the quote function can be applied to all variables.
The text was updated successfully, but these errors were encountered: