MCPcopy
hub / github.com/jesseduffield/lazygit / processOutput

Method processOutput

pkg/commands/oscommands/cmd_obj_runner.go:354–399  ·  view source on GitHub ↗
(
	reader io.Reader,
	writer io.Writer,
	promptUserForCredential func(CredentialType) <-chan string,
	closeFunc func() error,
	cmdObj *CmdObj,
)

Source from the content-addressed store, hash-verified

352}
353
354func (self *cmdObjRunner) processOutput(
355 reader io.Reader,
356 writer io.Writer,
357 promptUserForCredential func(CredentialType) <-chan string,
358 closeFunc func() error,
359 cmdObj *CmdObj,
360) {
361 checkForCredentialRequest := self.getCheckForCredentialRequestFunc()
362 task := cmdObj.GetTask()
363
364 scanner := bufio.NewScanner(reader)
365 scanner.Split(bufio.ScanBytes)
366 for scanner.Scan() {
367 newBytes := scanner.Bytes()
368 askFor, ok := checkForCredentialRequest(newBytes)
369 if ok {
370 responseChan := promptUserForCredential(askFor)
371 if responseChan == nil {
372 // Returning a nil channel means we should terminate the process.
373 // We achieve this by closing the pty that it's running in. Note that this won't
374 // work for the case where we're not running in a pty (i.e. on Windows), but
375 // in that case we'll never be prompted for credentials, so it's not a concern.
376 if err := closeFunc(); err != nil {
377 self.log.Error(err)
378 }
379 break
380 }
381
382 if task != nil {
383 task.Pause()
384 }
385 toInput := <-responseChan
386 if task != nil {
387 task.Continue()
388 }
389 // If the return data is empty we don't write anything to stdin
390 if toInput != "" {
391 _, _ = writer.Write([]byte(toInput))
392 }
393 }
394 }
395
396 if err := scanner.Err(); err != nil {
397 self.log.Error(err)
398 }
399}
400
401// having a function that returns a function because we need to maintain some state inbetween calls hence the closure
402func (self *cmdObjRunner) getCheckForCredentialRequestFunc() func([]byte) (CredentialType, bool) {

Callers 2

TestProcessOutputFunction · 0.80

Calls 6

GetTaskMethod · 0.80
PauseMethod · 0.65
ContinueMethod · 0.65
ErrorMethod · 0.45
WriteMethod · 0.45

Tested by 1

TestProcessOutputFunction · 0.64