rep icon indicating copy to clipboard operation
rep copied to clipboard

Optionally read code from stdin

Open plexus opened this issue 4 years ago • 6 comments

When no arguments are given then read from stdin instead. This way you can pipe code into rep.

Also prints a nicer warning when no port number is given and it can't find .nrepl-port.

plexus avatar Nov 01 '19 14:11 plexus

Thanks a lot for this! I’ve only taken a quick look, but it basically looks good. Please add test cases, though. I’ll look more closely tomorrow.

eraserhd avatar Nov 05 '19 06:11 eraserhd

I pushed a bunch of commits that get it building for me again. It uses Nix for local builds and CI, which keeps things reproducible, and I updated the documentation on how to build and test it. Your "fix native-image build" commit was merged, but the feature isn't.

Turns out, this feature is hanging the tests. I assume because there's a test that was doing something else and it is now being interpreted as wanting to read input, and that leads me to:

It's possible to want to evaluate the code - as getting the value of -, so we should use a separate option to specify input file, like -f <file>.

I think there's a problem here with the line numbers and -l when multiple forms are read from a file. We could probably send all the code in one message, but this disallows using this as a pipe. Is that the intent? Is it a good idea? Hrmm.

eraserhd avatar Nov 07 '19 20:11 eraserhd

Thanks, I'll have a look at the tests next week, and will change - to -f -.

this disallows using this as a pipe. Is that the intent?

Yes, the reason I implemented this feature is that I was generating some code with babashka, and trying to pipe it to rep.

plexus avatar Nov 08 '19 09:11 plexus

babashka looks nice!

I just realized that it's possible to use - to accept input from stdin, although, you will have to distinguish between - before and after --, which tools.cli may not do.

eraserhd avatar Nov 08 '19 14:11 eraserhd

Hi @eraserhd, I've rebased, added a CHANGELOG entry, updated the manpage, added a contributors section to the README, and checked in the patch.

It only reads from STDIN now if arguments is empty, i.e. if no expression is given. I figured that's good enough for now?

Thanks!

plexus avatar Nov 25 '19 21:11 plexus

If you add a test, I’ll merge it.

If you can figure out how to make it preserve line numbers for code read from stdin, that would be really nice.

eraserhd avatar Dec 02 '19 03:12 eraserhd