Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/efureev/go-commander
Commander
https://github.com/efureev/go-commander
Last synced: about 7 hours ago
JSON representation
Commander
- Host: GitHub
- URL: https://github.com/efureev/go-commander
- Owner: efureev
- Created: 2022-05-26T11:46:46.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-06-10T10:31:06.000Z (over 2 years ago)
- Last Synced: 2024-06-21T03:17:18.005Z (5 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
[![Go Report Card](https://goreportcard.com/badge/github.com/efureev/go-commander)](https://goreportcard.com/report/github.com/efureev/go-commander)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/efureev/go-commander)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/efureev/go-commander)
![GitHub](https://img.shields.io/github/license/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
})
}
```