You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should instead take in the lines one at a time instead of draining all at once. We can use the async generators approach we use for Internal's run (which is above it in the same file)
When digging around, I found an issue and first decided to fix it first (see #829).
So my understanding is that we want to avoid the into_vec(), and rather stream out the items in input.objects one by one, correct? If so, this seems like a fairly straightforward task of iterating over the stream instead of collecting it into a vec, unless I'm missing something 😅
@thegedge - that's right. You might have seen us using async_stream! { ... } Using this should let you iterate through each element rather than using into_vec() and send to the stdin of the external one line at a time rather than building something and then sending it all at once.
Given we have to construct a command string (e.g., cmd <it1> && cmd <it2> && ...) to pass to a shell, we're going to have to drain no matter what we do, right? Would the benefit here be that we could potentially do this without an intermediate Vec, or perhaps I'm missing something 😅
The only other option I can see is that instead of constructing an && command string to pass to a shell, we handle the executing of each of those individual commands in nushell, in which case I can definitely see how we can stream the result. Is that what you were thinking with this issue?
Oh that's a good point. It makes me wonder if we should move away from using && as well, and just evaluate the commands one after another instead (like you suggest)
I haven't thought through the impact of that, but I suspect we should investigate it.
I haven't thought through the impact of that, but I suspect we should investigate it.
One positive I can see is the ability to run a command against all inputs, regardless of whether or not one of the inputs results in the command failing (could be opt-in behaviour). Imagine something like this:
If you're up for it, I think we should give it a try. I agree that the logic of using && may not give you what you want (great example by the way)
Are you interested in refactoring and removing that assumption? Seems like we could generally have a better experience using the more relaxed approach you're suggesting
I'm up for it, if there's no urgency. I generally only have a little time on the weekends to work, and this weekend I won't have any 😅
Arguably, we could use ; instead of && to get a similar effect, but it's probably worth exploring doing all of this ourselves. I assume there's a long term goal to not have to shell out for these kinds of things?
Been a little busy lately, but I should have some free time this weekend to give it a shot. If it's out of my reach, we can hand it off. How does that sound?
So, after digging into this problem and sharing in Discord, it looks like @jonathandturner and I came to similar conclusions.
This is actually much more difficult than expected when we introduce $it to an external command. If we want nushell to be the orchestrator for each separate process, we'll have a separate stdout for every process. A naive approach to this would be to return a stream/vec of ClassifiedInputStream instances from ExternalCommand, but this also means a much larger refactor that perhaps doesn't make sense in the longer term.
I'll continue thinking about this but, as it stands, I don't have any immediate ideas of the best way to approach this. I may try to do some smaller refactors that will help me better understand how everything connects here. If we're lucky, maybe those refactors will help us get closer to where we want to be.
After digging around a ton, I think we need an abstraction of a pipe. That's really all that's happening when you do foo | bar, and I think we'll just need to manage this ourselves in nushell. Going to keep chipping away at this. I encourage others to take alternative approaches, but hopefully I can have a working prototype within a week 🤞
Activity
thegedge commentedon Oct 13, 2019
Hey, @jonathandturner. I'll try to tackle this one this weekend.
sophiajt commentedon Oct 13, 2019
@thegedge sounds good - feel free to ping here or on the discord if you want to brainstorm at any point.
thegedge commentedon Oct 14, 2019
When digging around, I found an issue and first decided to fix it first (see #829).
So my understanding is that we want to avoid the
into_vec(), and rather stream out the items ininput.objectsone by one, correct? If so, this seems like a fairly straightforward task of iterating over the stream instead of collecting it into a vec, unless I'm missing something 😅sophiajt commentedon Oct 15, 2019
@thegedge - that's right. You might have seen us using
async_stream! { ... }Using this should let you iterate through each element rather than usinginto_vec()and send to the stdin of the external one line at a time rather than building something and then sending it all at once.That's the theory at least :)
thegedge commentedon Oct 16, 2019
Given we have to construct a command string (e.g.,
cmd <it1> && cmd <it2> && ...) to pass to a shell, we're going to have to drain no matter what we do, right? Would the benefit here be that we could potentially do this without an intermediateVec, or perhaps I'm missing something 😅The only other option I can see is that instead of constructing an
&&command string to pass to a shell, we handle the executing of each of those individual commands in nushell, in which case I can definitely see how we can stream the result. Is that what you were thinking with this issue?sophiajt commentedon Oct 16, 2019
Oh that's a good point. It makes me wonder if we should move away from using && as well, and just evaluate the commands one after another instead (like you suggest)
I haven't thought through the impact of that, but I suspect we should investigate it.
thegedge commentedon Oct 16, 2019
One positive I can see is the ability to run a command against all inputs, regardless of whether or not one of the inputs results in the command failing (could be opt-in behaviour). Imagine something like this:
Where we can somehow process the results of these, and ignore the fact that
host asdjhasd.comis an NXDOMAIN output with an exist status of 1.sophiajt commentedon Oct 17, 2019
If you're up for it, I think we should give it a try. I agree that the logic of using && may not give you what you want (great example by the way)
Are you interested in refactoring and removing that assumption? Seems like we could generally have a better experience using the more relaxed approach you're suggesting
thegedge commentedon Oct 17, 2019
I'm up for it, if there's no urgency. I generally only have a little time on the weekends to work, and this weekend I won't have any 😅
Arguably, we could use
;instead of&&to get a similar effect, but it's probably worth exploring doing all of this ourselves. I assume there's a long term goal to not have to shell out for these kinds of things?andrasio commentedon Oct 31, 2019
@thegedge How are we doing? Got any updates?
thegedge commentedon Oct 31, 2019
Been a little busy lately, but I should have some free time this weekend to give it a shot. If it's out of my reach, we can hand it off. How does that sound?
thegedge commentedon Nov 3, 2019
So, after digging into this problem and sharing in Discord, it looks like @jonathandturner and I came to similar conclusions.
This is actually much more difficult than expected when we introduce
$itto an external command. If we want nushell to be the orchestrator for each separate process, we'll have a separatestdoutfor every process. A naive approach to this would be to return a stream/vec ofClassifiedInputStreaminstances fromExternalCommand, but this also means a much larger refactor that perhaps doesn't make sense in the longer term.I'll continue thinking about this but, as it stands, I don't have any immediate ideas of the best way to approach this. I may try to do some smaller refactors that will help me better understand how everything connects here. If we're lucky, maybe those refactors will help us get closer to where we want to be.
thegedge commentedon Nov 4, 2019
After digging around a ton, I think we need an abstraction of a pipe. That's really all that's happening when you do
foo | bar, and I think we'll just need to manage this ourselves in nushell. Going to keep chipping away at this. I encourage others to take alternative approaches, but hopefully I can have a working prototype within a week 🤞Dashes instead of underscores in command comparisons (nushell#816)