Skip to content

Commit a312a19

Browse files
committed
Fix reading from stdin without requiring -
1 parent d4f3ad9 commit a312a19

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

arguments.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ func (p *argParser) Eval() *Eval {
216216

217217
func (p *argParser) addTask(t StreamTask) {
218218
if input := p.inputTask(); input == nil {
219-
p.tasks = append(p.tasks, t)
219+
if len(p.tasks) == 0 {
220+
input = ReadFromTask(p.stdin, YAML)
221+
p.tasks = append(p.tasks, input, t)
222+
} else {
223+
p.tasks = append(p.tasks, t)
224+
}
220225
} else {
221226
p.tasks = append(p.tasks, input, t)
222227
}

arguments_test.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestParseArgs(t *testing.T) {
2525
Stdout string
2626
}
2727
tcs := []TestCase{
28-
{[]string{"-", "-e", "x"}, "null\n---\nnull\n", "null\n---\nnull\n"},
28+
{[]string{"-e", "x"}, "null\n---\nnull\n", "null\n---\nnull\n"},
2929
{nil, "1", "1\n"},
3030
{[]string{"-n"}, "", "null\n"},
3131
{[]string{"-n", "-v", "y==foo", "-e", "y"}, "", "foo\n"},
@@ -36,10 +36,7 @@ func TestParseArgs(t *testing.T) {
3636
{[]string{"testdata/foo.yaml", "-o", "j"}, "", `{"foo":"bar"}` + "\n"},
3737
{[]string{"testdata/foo.yaml", "testdata/bar.json"}, "", "foo: bar\n---\nbar: foo\n"},
3838
{[]string{"testdata/foo.yaml", "testdata/bar.json", "-a"}, "", "- foo: bar\n- bar: foo\n"},
39-
{[]string{
40-
"testdata/foo.yaml",
41-
"-e", `{bar: "baz"} + x`,
42-
}, "", "bar: baz\nfoo: bar\n"},
39+
{[]string{"testdata/foo.yaml", "-e", `{bar: "baz"} + x`}, "", "bar: baz\nfoo: bar\n"},
4340
// {[]string{""}, false, false, 2, "1", "1\n"},
4441
}
4542
for i, tc := range tcs {

0 commit comments

Comments
 (0)