You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use this convention quite often in programs I write using go-arg too. I've found it's best to implement at the level of the application using the library, rather than right within the library. I often have a string argument that is used as a filename, with a special case for when it's set to "-". Is this what you mean? Or is it that you would read lines from standard input to populate an argument?
I mean, one input source is standard input (rather than a named file).
Stdin could be coming from a pipe. Stdin could be coming from interactive typing (or pasting).
For example,
// GetStringFromStdin reads os.Stdin completely and returns a string.
func GetStringFromStdin() (string, error) {
println("==> Reading from Stdin; press ^D right after a newline to end")
bb, e := io.ReadAll(os.Stdin)
if e != nil {
return "", fmt.Errorf("Cannot read from Stdin: %w", e)
}
// MimeType = "text/plain"
return string(bb), nil
}
It is a Unix convention that a hyphen as a command line argument instructs a program to take input from standard input rather than from a named file.
Would it be possible to implement this ?
It certainly comes in handy when using a program with a pipe, or when pasting input.
The text was updated successfully, but these errors were encountered: