package script import ( "bufio" "context" "io" "os" "strings" ) // StdinReader reads from stdin type StdinReader struct { scanner bufio.Scanner } func NewStdinReader() *StdinReader { return &StdinReader{ scanner: *bufio.NewScanner(os.Stdin), } } // Read reads from stdin until \n character // then splits result at "," separator and returns // the resulting slice. // It returns EOF when nothing left to read. func (s *StdinReader) Read(_ context.Context) ([]string, error) { if !s.scanner.Scan() { err := s.scanner.Err() if err == nil { return nil, io.EOF } return nil, err } return strings.Split(s.scanner.Text(), ","), nil }