mitranim / gow

Missing watch mode for Go commands. Watch Go files and execute a command like "go run" or "go test"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support redirected input (and send all of it on every invocation)

tomasaschan opened this issue · comments

It's tempting to do something like gow run main.go < input.txt, but this will effectively run the application with that input once, and then basically freeze because the application is waiting for input but no more is coming.

gow (or some underlying library it uses) seemingly already detects that input is not a TTY, since it logs [gow] unable to read terminal state: inappropriate ioctl for device; it would be nice if it could in this case instead consume all of STDIN and store it, and then send it to the program on every invocation. If it can't detect it automatically, it could also be controlled with a flag, e.g. gow -T (for no-TTY; a lot of the good letters are already taken...).

If there's some other usage pattern that will allow me to do effectively the same thing, that'd be nice to document too! Currently I'm stuck with one terminal running gow -c build -o bin/my-app main.go and another ls bin/ | entr -rc sh -c 'bin/my-app < input.txt' which is just annoying... :)

To clarify the error message you're seeing: by default, gow tries to switch the terminal into "raw mode" which allows to support hotkeys; when this operation fails, it logs this error and continues without raw mode; this can be disabled with gow -r=false.

We just want to move < input.txt from "outside" gow to "inside" each gow invocation. gow just wants to invoke one subprocess with the given arguments, and doesn't have features like redirecting stdin from a file; that's really out of scope. However, gow can be used to invoke any program including a shell script; invoking go just happens to be the default. The most practical solution for your case is a shell script. Adapting from #37 (comment):

touch go.sh
chmod +x go.sh

Content of go.sh:

#!/bin/sh

go @$ < input.txt

Usage:

gow -g=./go.sh -v -c run .