nak/helpers.go
2023-10-20 20:57:29 -03:00

30 lines
463 B
Go

package main
import (
"bytes"
"io"
"os"
"github.com/urfave/cli/v2"
)
func getStdin() string {
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
read := bytes.NewBuffer(make([]byte, 0, 1000))
_, err := io.Copy(read, os.Stdin)
if err == nil {
return read.String()
}
}
return ""
}
func getStdinOrFirstArgument(c *cli.Context) string {
target := c.Args().First()
if target != "" {
return target
}
return getStdin()
}