Returns a single-use iterator over the output of the command, line by line.
()
| 57 | |
| 58 | // Returns a single-use iterator over the output of the command, line by line. |
| 59 | func (s Subprocess) StdoutLines() (iter.Seq[string], func() error) { |
| 60 | var iterErr error |
| 61 | |
| 62 | seq := func(yield func(string) bool) { |
| 63 | scanner := bufio.NewScanner(s.stdout) |
| 64 | for scanner.Scan() { |
| 65 | if !yield(scanner.Text()) { |
| 66 | return |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | iterErr = scanner.Err() |
| 71 | } |
| 72 | |
| 73 | finish := func() error { |
| 74 | if iterErr != nil { |
| 75 | iterErr = fmt.Errorf("error while scanning: %w", iterErr) |
| 76 | } |
| 77 | |
| 78 | return iterErr |
| 79 | } |
| 80 | |
| 81 | return seq, finish |
| 82 | } |
| 83 | |
| 84 | // Returns a single-use iterator over the output from git log. |
| 85 | // |