Skip to content

Commit 36eafd4

Browse files
committed
use new RunAndGet in README.md because it is more simpler
1 parent 0d01ac2 commit 36eafd4

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ cat log_file.txt | grep error | wc -l
1515
package main
1616

1717
import (
18-
"bytes"
1918
"fmt"
2019
"github.com/rainu/go-command-chain"
2120
)
2221

2322
func main() {
24-
output := &bytes.Buffer{}
25-
26-
err := cmdchain.Builder().
23+
stdOut, stdErr, err := cmdchain.Builder().
2724
Join("cat", "log_file.txt").
2825
Join("grep", "error").
2926
Join("wc", "-l").
30-
Finalize().WithOutput(output).Run()
27+
Finalize().RunAndGet()
3128

3229
if err != nil {
3330
panic(err)
3431
}
35-
fmt.Printf("Errors found: %s", output)
32+
if stdErr != "" {
33+
panic(stdErr)
34+
}
35+
fmt.Printf("Errors found: %s", stdOut)
3636
}
3737
```
3838

example_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,19 @@ func ExampleBuilder_run() {
237237
}
238238
println(output.String())
239239
}
240+
241+
func ExampleBuilder_runAndGet() {
242+
//it's the same as in shell: ls -l | grep README | wc -l
243+
sout, serr, err := cmdchain.Builder().
244+
Join("ls", "-l").
245+
Join("grep", "README").
246+
Join("wc", "-l").
247+
Finalize().
248+
RunAndGet()
249+
250+
if err != nil {
251+
panic(err)
252+
}
253+
println("OUTPUT: " + sout)
254+
println("ERROR: " + serr)
255+
}

0 commit comments

Comments
 (0)