https://github.com/efureev/go-commander
Commander
https://github.com/efureev/go-commander
Last synced: about 2 months ago
JSON representation
Commander
- Host: GitHub
- URL: https://github.com/efureev/go-commander
- Owner: efureev
- Created: 2022-05-26T11:46:46.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-10T10:31:06.000Z (almost 3 years ago)
- Last Synced: 2025-01-15T09:02:36.725Z (3 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Commander
[](https://goreportcard.com/report/github.com/efureev/go-commander)


Command executor
## Installation
```shell
go get github.com/efureev/go-commander
```## Usage
```go
package mainimport (
commander "github.com/efureev/go-commander"
)func main() {
cmdr := commander.NewCommander().
Add(
commander.NewCommand(`info`).
OnRun(func(cmd *commander.Command) error {
println(cmd.Name)
return nil
}),
cmdFinish(`finish`),
// ...
)cmdr.Run()
}func cmdFinish(t string) *commander.Command {
return commander.NewCommand(`Finish!`).
OnPrepare(func(cmd *commander.Command) error {
println(`OnPrepare`)
return nil
}).
OnRun(func(cmd *commander.Command) error {
println(t)
return nil
}).
OnDone(func(cmd *commander.Command) error {
println(`OnDone`)
return nil
})
}
```