blink/v1/internal/file/pipe.go
2024-07-08 02:04:54 +01:00

36 lines
533 B
Go

package file
import (
"bufio"
"os"
"strings"
)
// Get the pipe
func Pipe() []string {
// Store lines
var lines []string
// Get pipe
pipe, _ := os.Stdin.Stat()
// Piped found
if (pipe.Mode() & os.ModeCharDevice) == 0 {
// Create scanner
scanner := bufio.NewScanner(os.Stdin)
// Go through scanner
for scanner.Scan() {
// Store line
line := scanner.Text()
// Ignore empty & commented lines
if line != "" && !strings.HasPrefix(line, "#") {
lines = append(lines, line)
}
}
}
return lines
}