# Executing a program that consumes all of stdin.
stdin echo-stdin
exec cue cmd echo
cmp stdout echo-stdout

# A command with two prompts, where the input is three lines.
# The first and second line should be the two answers.
stdin intro-stdin
exec cue cmd intro
cmp stdout intro-stdout

# Like the previous test case, but with more whitespace in the answers.
# The response strings should contain the entire lines including the whitespace.
stdin intro-spaces-stdin
exec cue cmd intro
cmp stdout intro-spaces-stdout

# Run a command with exec.Run which doesn't actually read stdin,
# but still passes through stdin to os/exec per exec.Run's default.
# This will hang unless the task's stdin is an os.File,
# as otherwise io.Copy does not finish; see https://go.dev/issue/7990.
exec cue_stdinpipe cmd noreads
cmp stdout noreads-stdout

-- echo-stdin --
Hello World!
-- echo-stdout --
Hello World!
-- intro-stdin --
John Doe
Capital City
Extra input that shouldn't be used.
-- intro-stdout --
What is your name? Where do you live? 
Your full name is John Doe and you live in Capital City.
-- intro-spaces-stdin --
  John  Doe  
	Capital City
Extra input that shouldn't be used.
-- intro-spaces-stdout --
What is your name? Where do you live? 
Your full name is   John  Doe   and you live in 	Capital City.
-- noreads-stdout --
not reading any stdin
-- hello_tool.cue --
package hello

import (
	"tool/cli"
	"tool/exec"
)

command: echo: {
    echo: {
        kind:   "exec"
        cmd:    "cat"
        stdout: string
    }

    pass: {
        kind:   "exec"
        cmd:    "cat"
        stdin:  echo.stdout
    }
}

command: intro: {
	askName: cli.Ask & {
		prompt:   "What is your name?"
		response: string
	}

	askPlace: cli.Ask & {
		order:    askName.response
		prompt:   "Where do you live?"
		response: string
	}

	results: cli.Print & {
		text: "\nYour full name is \(askName.response) and you live in \(askPlace.response)."
	}
}

command: noreads: {
	first: exec.Run & {
		cmd: ["echo", "not reading any stdin"]
	}
}
-- cue.mod/module.cue --
module: "test.example"
language: version: "v0.9.0"
