-
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
Add option to run arbitrary command from project root #114
Comments
Closing, since I'm not sure this is really that important. Feel free to comment if you want this! |
Gah, I can't decide on this. I think I should just implement it and see how it feels. |
Couldn't someone just write a |
They definitely could, and it would be more ergonomic, however because of the weird way that argument substitution works, arguments would be split in unexpected ways. For example, if the recipe was written: cmd +args:
{{args}} Then:
would be different from:
Since in the second case the |
Then it sounds like the proper solution is to add some annotation which allows any multiple-argument token to be switched from |
I agree that some kind of annotation would be a better solution, but it might not be worth it, given that this feature is probably not high priority. Unless there are other things that it would enable. I think the best solution would actually be to do #161. If there was a good shell which was implemented as a library, just could use that directly. Having access to the execution context of the shell would enable all sorts of really great features. All just variables could be made available to the shell without having to export them and polluting the namespace of child processes. x = 'a b; c'
foo:
echo $x 1038 - 1145 and The shell runtime would distinguish between scalar values and list values (which zsh and bash already do), so if you had: man args+:
man $args Then it would correctly forward two arguments to I'm actually tempted to implement the Of course, it has the huge downside of being different from what users have installed on their system and what they're used to. What are your thoughts? |
The problem is that there are very good reasons for having access to both The space-splitting behaviour is necessary any time you want to pass a string of options to a subcommand without that subcommand taking up the one variadic position. The quoting-preserving behaviour is essential for properly implementing any situation where you're receiving filenames in your variadic arguments. To this day, legacy document-handling tooling like LaTeX (and, thus, LyX) is hampered by incompatibilities with spaces in filenames... in something meant to process books... books that tend to have spaces in their titles and, thus, intuitively, should have spaces in their filenames. build-docs opts paths+:
doc-thingy $opts "$paths" If there's no syntax to make
That really is a huge downside because not only is rc strange and unfamiliar, I seriously doubt "Makefiles, with rc syntax" exists as a syntax definition for Just to piggy-back off of, and people rely heavily on syntax highlighting to make up for a limited understanding of a new grammar. I'll need to get back to you on it when I'm not so tired though. EDIT: I should clarify. "strange and unfamiliar" in the sense that it falls into the uncanny valley of shell scripting, looking just similar enough to make me very unnerved about what gotchas are likely to be lurking in my assumptions about how to use it. (And, as someone whose experience with functional programming doesn't extend much further than loving things like first-class functions, list comprehensions, and generators in Python and reading up on some other concepts like tail recursion (so, more experienced than most mainstream programmers), I have an impulsive impression that seeing I still think the "gotta write syntax highlighting for 50 million different editors and wait for it to get into LTS distro releases in the case of the non-extensible ones" problem is more significant. |
Yeah, that difference between behaviors is exactly the reason that the rc shell has pervasive supports for lists. There's a great paper about it. I won't be able to summarize well, but it goes into detail about how string splitting and re-scanning/splitting of string variables contributes to the complexity of the Bourne shell. It also has a terrifying quote:
Or at least, it's a terrifying quote when I think about trying to implement a Bourne shell in rust. The point about syntax highlighting is a good one. And, don't get me wrong, I definitely think that not being However, I think I might be able to implement In terms of supporting this particular use case, we could introduce a function-call syntax, and provide a built-in function to quote items of an array. This could look like:
This has a lot of issues though. For example, what happens when a string in Ultimately I think that trying to get too clever about integrating with a shell (or any other language that a task might be written in) that isn't part of just itself is probably a bad idea, since there are too many factors to control. Even though it's a lot more work, I think integrating with a rust-written shell library is the way to go. |
What about Ion for a shell? |
Ion is super cool, but seems to be a bit of a moving target at the moment. Also, I'm hoping for a shell which is very simple, is as close to |
Boy, that takes me back. It must have been somewhere between 5 or 10 years since I ran across that quote.
Agreed. Trying to puppet an external shell sounds like an exercise in insanity.
Is it really necessary to write a whole Bourne-style shell parser to handle tasks with no shebang? I'd always thought that Make and inspired tools processed each line in isolation using some kind of restricted subset of Bourne shell syntax. Given that just actually has a proper way to specify full-syntax Bourne shell (use a shebang) and the aforementioned perception (not actually sure if it's a misconception), how much complexity is someone going to try to cram into a single line when it'd be much less painful to just use a shebang? |
I worry that providing a shell language that was close to but not identical to Also, if it was a full fledged |
The question is whether users expect that in the first place. I don't know about you, but I've never seen a Bourne shell which implements the DOS batch file "prefix a line with @ to prevent echoing it" behaviour. |
By the way, now that set positional-arguments
cmd +args:
"$@" which ensures the individual arguments stay quoted. |
@kwshi Good point! You're noticing a lot of places where I'll most likely make it the default in 1.0 (see #769 and #808). It's a breaking change, since a custom interpreter set with |
I actually wanted this today, so I implemented it. Of course, it's also possible to do this nicely with a recipe and |
Add a option which allows running a command from the project root:
# for example, to edit your Cargo.toml file from any subdirectory of your project $ just --cmd vim Cargo.toml
The text was updated successfully, but these errors were encountered: