https://github.com/songgao/go.pipeline
go.pipeline is a utility library that imitates unix pipeline. It simplifies chaining unix commands (and other stuff) in Go.
https://github.com/songgao/go.pipeline
Last synced: 25 days ago
JSON representation
go.pipeline is a utility library that imitates unix pipeline. It simplifies chaining unix commands (and other stuff) in Go.
- Host: GitHub
- URL: https://github.com/songgao/go.pipeline
- Owner: songgao
- Created: 2013-02-14T16:33:23.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2022-04-29T04:55:35.000Z (about 3 years ago)
- Last Synced: 2025-04-23T12:58:14.269Z (25 days ago)
- Language: Go
- Size: 7.81 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go.pipeline
go.pipeline is a utility library that imitates unix pipeline. It simplifies chaining unix commands (and other stuff) in Go.## Installation
```
go get -u github.com/songgao/go.pipeline
```## Documentation
[http://godoc.org/github.com/songgao/go.pipeline](http://godoc.org/github.com/songgao/go.pipeline)## Examples
### Execute a single unix command
```go
package mainimport "github.com/songgao/go.pipeline"
func main() {
pipeline.StartPipelineWithCommand("uname", "-a").PrintAll()
}
```### Chain multiple unix commands
Following code is equal to `ls -h -l /bin | egrep --color=always -e "\\ *[0-9.]*M\\ *"`, plus a counter pre-pended to each line.
```go
package mainimport (
"fmt"
"github.com/songgao/go.pipeline"
)func main() {
counter := 0pipeline.NewPipeline().
ChainCommand("ls", "-h", "-l", "/bin").ChainCommand("egrep", "--color=always", "-e", `\ *[0-9.]*M\ *`).
ChainLineProcessor(func(in string) string {
counter++
return fmt.Sprintf("%d:\t%s", counter, in)
}, nil).PrintAll()
}
```
An equivalent shorter version is:
```go
package mainimport (
"fmt"
"github.com/songgao/go.pipeline"
)func main() {
counter := 0pipeline.NewPipeline().
C("ls", "-h", "-l", "/bin").C("egrep", "--color=always", "-e", `\ *[0-9.]*M\ *`).
L(func(in string) string {
counter++
return fmt.Sprintf("%d:\t%s", counter, in)
}, nil).P()
}
```### Colorize `go build` output
Check out `colorgo` project: [https://github.com/songgao/colorgo](https://github.com/songgao/colorgo)## TODO
* tee, etc.
* custom Station
* package doc
* more organized README.md## License
[BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause)