func()

in command-runner/internal/containers/finch/finch_service.go [94:132]


func (f *finch) RunWithStdio(ctx context.Context, stdin io.Reader, stdout io.Writer, stderr io.Writer, args ...string) error {
	finchCmd := fmt.Sprintf("%s/bin/finch", f.installDir)

	args = append([]string{finchCmd}, args...)
	cmd := exec.CommandContext(ctx, finchCmd) //#nosec G204
	cmd.Path = finchCmd
	cmd.Args = args
	cmd.Stdin = stdin

	cmdout, err := cmd.StdoutPipe()
	if err != nil {
		return err
	}
	cmderr, err := cmd.StderrPipe()
	if err != nil {
		return err
	}

	log.Ctx(ctx).Debug().Msgf("🐦 %s", strings.Join(args, " "))
	if common.Dryrun(ctx) {
		log.Ctx(ctx).Debug().Msgf("exit for dryrun")
		return nil
	}

	if err := cmd.Start(); err != nil {
		return fmt.Errorf("unable to start command: %w", err)
	}
	if stdout != nil {
		go streamPipe(stdout, cmdout)
	}
	if stderr != nil {
		go streamPipe(stderr, cmderr)
	}
	err = cmd.Wait()
	if err != nil {
		return fmt.Errorf("finch command failed: %w", err)
	}
	return nil
}