shelly/Readme.md

47 lines
1020 B
Markdown
Raw Permalink Normal View History

2021-10-24 21:31:09 +00:00
# Shelly
An abstraction for shell directly in GO
## Goal
2021-10-25 00:42:20 +00:00
Simplify process spawning and execution on top of exec.Command function.
2021-10-24 21:31:09 +00:00
2021-10-25 00:42:20 +00:00
The proposal is: use a string based approach for launching other process - as if you were calling a shell, but instead,
2021-10-24 21:31:09 +00:00
its go directly executing your commands.
Example:
```go
package main
import "go.digitalcircle.com.br/open/shelly"
import "os"
import "os/exec"
2021-10-25 00:42:20 +00:00
func main() {
2021-10-25 21:44:30 +00:00
_, err := shelly.Exec(`
2021-10-25 00:42:20 +00:00
ls -larth &
pwd &
2021-10-24 21:31:09 +00:00
whoami
2021-10-25 21:44:30 +00:00
date`,
&shelly.Opts{
Await: false,
Wd: ".",
Debug: true,
SetupProc: func(cmd *exec.Cmd) {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
},
})
2021-10-24 21:31:09 +00:00
if err != nil {
panic(err)
}
}
```
2021-10-25 00:42:20 +00:00
Please note: Commands may be connected by `;` and `\n`. In any case they will be executed sequentially. Lines terminated
by `&` will be executed in parallel.
In case the Await property is true, shelly will wait for all lines to be executed (including parallel ones), otherwise
it will return as soon as serial tasks are finished (if any)