-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpipable.go
94 lines (76 loc) · 2.17 KB
/
pipable.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package someutils
import "io"
//a Pipable can be executed on a pipeline
type Pipable interface {
Invoke(i *Invocation) (error, int)
}
//a PipableSimple can be executed on a pipeline when wrapped inside a PipableSimpleWrapper
type PipableSimple interface {
Exec(inPipe io.Reader, outPipe io.Writer, errPipe io.Writer) (error, int)
}
// a Named Pipable can be registered for use by e.g. xargs
type NamedPipable interface {
Pipable
Named
}
//PipableUtil represents a util which can be initialized by flags & executed on a Pipeline
type CliPipable interface {
NamedPipable
Cliable
}
type PipableWrapper struct {
PipableSimple
}
type Named interface {
Name() string
}
type Cliable interface {
ParseFlags(call []string, errPipe io.Writer) (error, int)
}
type NamedPipableSimple interface {
PipableSimple
Named
}
type CliPipableSimple interface {
NamedPipableSimple
Cliable
}
type PipableSimpleWrapper struct {
PipableSimple
}
type NamedPipableSimpleWrapper struct {
NamedPipableSimple
}
type CliPipableSimpleWrapper struct {
CliPipableSimple
}
func Wrap(ps PipableSimple) Pipable {
return &PipableSimpleWrapper{ps}
}
func WrapNamed(ps NamedPipableSimple) NamedPipable {
return &NamedPipableSimpleWrapper{ps}
}
func WrapCliPipable(ps CliPipableSimple) CliPipable {
return &CliPipableSimpleWrapper{ps}
}
/*
func (w PipableWrapper) ExecFull(inPipe io.Reader, outPipe io.Writer, errInPipe io.Reader, errOutPipe io.Writer, signalChan chan int) (error, int) {
go autoPipe(errMainPipe.Out, errMainPipe.In)
return w.PipableSimple.Exec(inPipe, outPipe, errMainPipe.Out)
}
*/
func (npsw *NamedPipableSimpleWrapper) Invoke(i *Invocation) (error, int) {
return invoke(npsw.NamedPipableSimple, i)
}
func (psw *PipableSimpleWrapper) Invoke(i *Invocation) (error, int) {
return invoke(psw.PipableSimple, i)
}
func (cpsw *CliPipableSimpleWrapper) Invoke(i *Invocation) (error, int) {
return invoke(cpsw.CliPipableSimple, i)
}
type PipableFactory func() Pipable
//type NamedPipableFactory func() NamedPipable
type CliPipableFactory func() CliPipable
type PipableSimpleFactory func() PipableSimple
type NamedPipableSimpleFactory func() NamedPipableSimple
type CliPipableSimpleFactory func() CliPipableSimple