just icon indicating copy to clipboard operation
just copied to clipboard

Implement loading justfile from stdin

Open drzymalanet opened this issue 1 year ago • 6 comments

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:

  1. Move Search{} functionality into Source{}
  2. Implement Source::from_stdin()
  3. Add "-" detection to the argument parser.

Here is the first of the commits, more commits will be added while work progresses.

drzymalanet avatar Mar 03 '24 23:03 drzymalanet

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 avatar May 15 '24 01:05 casey

@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?

drzymalanet avatar May 15 '24 12:05 drzymalanet

There are two options I can think of:

  1. Add an additional field to Search, which is a string containing the loaded source
  2. Make Search::justfile an enum, like JustfileSource

I would try out 1 first and see how it looks and see if it causes any problems, or requires a big refactor.

casey avatar May 16 '24 01:05 casey

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.

drzymalanet avatar Jun 11 '24 00:06 drzymalanet

This looks like a good approach to me!

casey avatar Jun 13 '24 20:06 casey

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!

drzymalanet avatar Aug 16 '24 17:08 drzymalanet