Skip to content

Commit 445d16d

Browse files
committed
remove IOPreferenceNil
It doesn't really mean much of anything to specify IOPreferenceNil. Nothing uses it, which isn't surprising because it's not clear what it would even mean anywhere other than the begin/end of a pipeline.
1 parent 33ca03c commit 445d16d

3 files changed

Lines changed: 24 additions & 31 deletions

File tree

pipe/command.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,10 @@ func (s *commandStage) Name() string {
7070
}
7171

7272
func (s *commandStage) Preferences() StagePreferences {
73-
prefs := StagePreferences{
73+
return StagePreferences{
7474
StdinPreference: IOPreferenceFile,
7575
StdoutPreference: IOPreferenceFile,
7676
}
77-
if s.cmd.Stdin != nil {
78-
prefs.StdinPreference = IOPreferenceNil
79-
}
80-
if s.cmd.Stdout != nil {
81-
prefs.StdoutPreference = IOPreferenceNil
82-
}
83-
84-
return prefs
8577
}
8678

8779
func (s *commandStage) Start(

pipe/pipe_matching_test.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ import (
2222
const (
2323
IOPreferenceUndefinedNopCloser pipe.IOPreference = iota + 100
2424
IOPreferenceFileNopCloser
25+
26+
// expectNil is a test-only expectation token meaning that the
27+
// stage should be passed a `nil` stdin / stdout (which happens at
28+
// the beginning / end of a pipeline when no overall stdin / stdout
29+
// is configured). It is not a real `IOPreference`.
30+
expectNil
2531
)
2632

2733
func file(t *testing.T) *os.File {
@@ -143,7 +149,7 @@ func prefString(pref pipe.IOPreference) string {
143149
return "other"
144150
case pipe.IOPreferenceFile:
145151
return "*os.File"
146-
case pipe.IOPreferenceNil:
152+
case expectNil:
147153
return "nil"
148154
case IOPreferenceUndefinedNopCloser:
149155
return "nopCloser(other)"
@@ -200,7 +206,7 @@ func TestPipeTypes(t *testing.T) {
200206
name: "func",
201207
opts: []pipe.Option{},
202208
stages: []pipe.Stage{
203-
newPipeSniffingFunc(pipe.IOPreferenceNil, pipe.IOPreferenceNil),
209+
newPipeSniffingFunc(expectNil, expectNil),
204210
},
205211
},
206212
{
@@ -209,7 +215,7 @@ func TestPipeTypes(t *testing.T) {
209215
pipe.WithStdin(file(t)),
210216
},
211217
stages: []pipe.Stage{
212-
newPipeSniffingFunc(IOPreferenceFileNopCloser, pipe.IOPreferenceNil),
218+
newPipeSniffingFunc(IOPreferenceFileNopCloser, expectNil),
213219
},
214220
},
215221
{
@@ -218,7 +224,7 @@ func TestPipeTypes(t *testing.T) {
218224
pipe.WithStdout(file(t)),
219225
},
220226
stages: []pipe.Stage{
221-
newPipeSniffingFunc(pipe.IOPreferenceNil, IOPreferenceFileNopCloser),
227+
newPipeSniffingFunc(expectNil, IOPreferenceFileNopCloser),
222228
},
223229
},
224230
{
@@ -227,7 +233,7 @@ func TestPipeTypes(t *testing.T) {
227233
pipe.WithStdoutCloser(file(t)),
228234
},
229235
stages: []pipe.Stage{
230-
newPipeSniffingFunc(pipe.IOPreferenceNil, pipe.IOPreferenceFile),
236+
newPipeSniffingFunc(expectNil, pipe.IOPreferenceFile),
231237
},
232238
},
233239
{
@@ -244,7 +250,7 @@ func TestPipeTypes(t *testing.T) {
244250
name: "cmd",
245251
opts: []pipe.Option{},
246252
stages: []pipe.Stage{
247-
newPipeSniffingCmd(pipe.IOPreferenceNil, pipe.IOPreferenceNil),
253+
newPipeSniffingCmd(expectNil, expectNil),
248254
},
249255
},
250256
{
@@ -253,7 +259,7 @@ func TestPipeTypes(t *testing.T) {
253259
pipe.WithStdin(file(t)),
254260
},
255261
stages: []pipe.Stage{
256-
newPipeSniffingCmd(IOPreferenceFileNopCloser, pipe.IOPreferenceNil),
262+
newPipeSniffingCmd(IOPreferenceFileNopCloser, expectNil),
257263
},
258264
},
259265
{
@@ -262,7 +268,7 @@ func TestPipeTypes(t *testing.T) {
262268
pipe.WithStdout(file(t)),
263269
},
264270
stages: []pipe.Stage{
265-
newPipeSniffingCmd(pipe.IOPreferenceNil, IOPreferenceFileNopCloser),
271+
newPipeSniffingCmd(expectNil, IOPreferenceFileNopCloser),
266272
},
267273
},
268274
{
@@ -271,7 +277,7 @@ func TestPipeTypes(t *testing.T) {
271277
pipe.WithStdoutCloser(file(t)),
272278
},
273279
stages: []pipe.Stage{
274-
newPipeSniffingCmd(pipe.IOPreferenceNil, pipe.IOPreferenceFile),
280+
newPipeSniffingCmd(expectNil, pipe.IOPreferenceFile),
275281
},
276282
},
277283
{
@@ -301,7 +307,7 @@ func TestPipeTypes(t *testing.T) {
301307
pipe.WithStdout(file(t)),
302308
},
303309
stages: []pipe.Stage{
304-
newPipeSniffingFunc(pipe.IOPreferenceNil, pipe.IOPreferenceFile),
310+
newPipeSniffingFunc(expectNil, pipe.IOPreferenceFile),
305311
newPipeSniffingCmd(pipe.IOPreferenceFile, IOPreferenceFileNopCloser),
306312
},
307313
},
@@ -312,23 +318,23 @@ func TestPipeTypes(t *testing.T) {
312318
},
313319
stages: []pipe.Stage{
314320
newPipeSniffingCmd(IOPreferenceUndefinedNopCloser, pipe.IOPreferenceFile),
315-
newPipeSniffingFunc(pipe.IOPreferenceFile, pipe.IOPreferenceNil),
321+
newPipeSniffingFunc(pipe.IOPreferenceFile, expectNil),
316322
},
317323
},
318324
{
319325
name: "cmd-cmd",
320326
opts: []pipe.Option{},
321327
stages: []pipe.Stage{
322-
newPipeSniffingCmd(pipe.IOPreferenceNil, pipe.IOPreferenceFile),
323-
newPipeSniffingCmd(pipe.IOPreferenceFile, pipe.IOPreferenceNil),
328+
newPipeSniffingCmd(expectNil, pipe.IOPreferenceFile),
329+
newPipeSniffingCmd(pipe.IOPreferenceFile, expectNil),
324330
},
325331
},
326332
{
327333
name: "hybrid1",
328334
opts: []pipe.Option{},
329335
stages: []pipe.Stage{
330336
newPipeSniffingStage(
331-
pipe.IOPreferenceUndefined, pipe.IOPreferenceNil,
337+
pipe.IOPreferenceUndefined, expectNil,
332338
pipe.IOPreferenceUndefined, pipe.IOPreferenceUndefined,
333339
),
334340
newPipeSniffingStage(
@@ -337,7 +343,7 @@ func TestPipeTypes(t *testing.T) {
337343
),
338344
newPipeSniffingStage(
339345
pipe.IOPreferenceUndefined, pipe.IOPreferenceFile,
340-
pipe.IOPreferenceUndefined, pipe.IOPreferenceNil,
346+
pipe.IOPreferenceUndefined, expectNil,
341347
),
342348
},
343349
},
@@ -346,7 +352,7 @@ func TestPipeTypes(t *testing.T) {
346352
opts: []pipe.Option{},
347353
stages: []pipe.Stage{
348354
newPipeSniffingStage(
349-
pipe.IOPreferenceUndefined, pipe.IOPreferenceNil,
355+
pipe.IOPreferenceUndefined, expectNil,
350356
pipe.IOPreferenceUndefined, pipe.IOPreferenceFile,
351357
),
352358
newPipeSniffingStage(
@@ -355,7 +361,7 @@ func TestPipeTypes(t *testing.T) {
355361
),
356362
newPipeSniffingStage(
357363
pipe.IOPreferenceUndefined, pipe.IOPreferenceUndefined,
358-
pipe.IOPreferenceUndefined, pipe.IOPreferenceNil,
364+
pipe.IOPreferenceUndefined, expectNil,
359365
),
360366
},
361367
},

pipe/stage.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,4 @@ const (
138138
// IOPreferenceFile indicates that the stage would prefer for the
139139
// specified stdin / stdout to be an `*os.File`, to avoid copying.
140140
IOPreferenceFile
141-
142-
// IOPreferenceNil indicates that the stage does not use the
143-
// specified stdin / stdout, so `nil` should be passed in. This
144-
// should only happen at the beginning / end of a pipeline.
145-
IOPreferenceNil
146141
)

0 commit comments

Comments
 (0)