/
println.go
50 lines (44 loc) · 1 KB
/
println.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2017 Opsidian Ltd.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package blocks
import (
"bufio"
"context"
"fmt"
"io"
"github.com/conflowio/conflow/src/conflow"
)
// Println will write a string followed by a new line to the standard output
// @block "task"
type Println struct {
// @id
id conflow.ID
// @value
// @required
value interface{}
// @dependency
stdout io.Writer
}
func (p *Println) ID() conflow.ID {
return p.id
}
func (p *Println) Run(ctx context.Context) (conflow.Result, error) {
switch v := p.value.(type) {
case io.ReadCloser:
scanner := bufio.NewScanner(v)
for scanner.Scan() {
if _, err := fmt.Fprintln(p.stdout, scanner.Text()); err != nil {
return nil, err
}
}
return nil, nil
default:
if _, err := fmt.Fprintln(p.stdout, p.value); err != nil {
return nil, err
}
}
return nil, nil
}