Implement loading justfile from stdin
I think it would be nice to have the possibility to pipe justfiles into just, like so:
cat input.txt | just --dump --justfile - > output.txt
It would work by detecting a special symbol "-" as the -f / --justfile argument.
Benefits:
- Some code editors like helix require this in order to make auto formatting to work,
- Many command line tools work like this and it seems it will not hurt to have,
The plan:
- Move
Search{}functionality intoSource{} - Implement
Source::from_stdin() - Add "-" detection to the argument parser.
Here is the first of the commits, more commits will be added while work progresses.
This seems reasonable, but this PR looks a bit too complicated and I think some of the changes are unnecessary.
I would create two new SearchConfig variants, WithStdin, and WithStdinAndWorkingDirectory, and handle those two cases separately in Search::find.
@casey I have added the variants, now we need to change Search.justfile type because it is a PathBuf which does not fit to the stdin stream. It seems to me that changing it to an Rc<dyn std::io::Read> or a custom JustfileSource would be some options. What do you think?
There are two options I can think of:
- Add an additional field to
Search, which is a string containing the loaded source - Make
Search::justfilean enum, likeJustfileSource
I would try out 1 first and see how it looks and see if it causes any problems, or requires a big refactor.
Sorry for closing and reopening. It was by mistake.
@casey Please have a look at the new commit. I have added a JustfileKind enum to the Search struct. It does not feel right, but I have no idea how to make it better without a bigger refactor. Let me know what you think.
This looks like a good approach to me!
Hi @casey I have changed a little the implementation of this PR. Previous approach did not felt right for me. I think the new approach makes more sense. However, I stumbled upon a failing integration test: working_directory::justfile_without_working_directory. It seems it runs the command in a subshell, which makes it hard to find out what's the problem. Any advice on how to trace this?
Let me know what you think about the new changes.
Thanks!