Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shipengqi/action
Inspired by Cobra. Cobra is a library for creating powerful modern CLI applications. "action" can be used to create a more fine-grained behavior of a command.
https://github.com/shipengqi/action
action cobra
Last synced: 2 months ago
JSON representation
Inspired by Cobra. Cobra is a library for creating powerful modern CLI applications. "action" can be used to create a more fine-grained behavior of a command.
- Host: GitHub
- URL: https://github.com/shipengqi/action
- Owner: shipengqi
- License: apache-2.0
- Created: 2022-09-29T02:01:12.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-18T14:33:55.000Z (5 months ago)
- Last Synced: 2024-10-05T02:33:55.559Z (3 months ago)
- Topics: action, cobra
- Language: Go
- Homepage:
- Size: 63.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# action
Inspired by [Cobra](https://github.com/spf13/cobra). Cobra is a library for creating powerful modern CLI applications.
"action" can be used to create a more fine-grained behavior of a command.[![Test Status](https://github.com/shipengqi/action/actions/workflows/test.yml/badge.svg)](https://github.com/shipengqi/action/actions/workflows/test.yml)
[![Codecov](https://codecov.io/gh/shipengqi/action/branch/main/graph/badge.svg?token=SMU4SI304O)](https://codecov.io/gh/shipengqi/action)
[![Release](https://img.shields.io/github/release/shipengqi/action.svg)](https://github.com/shipengqi/action/releases)
[![License](https://img.shields.io/github/license/shipengqi/action)](https://github.com/shipengqi/action/blob/main/LICENSE)## Getting Started
```go
cmd := &cobra.Command{
Use: "example-cmd",
Short: "A sample command.",
RunE: func(cmd *cobra.Command, args []string) error {
act := &action.Action{
Name: "example-action",
Run: func(act *action.Action) error { return nil },
}
_ = act.AddAction(
newSubAction1(),
newSubAction2(),
)act.Execute()
},
}func newSubAction1() *action.Action {
return &action.Action{
Name: "sub-action1",
Executable: func(act *action.Action) bool {
// do something
return true
},
Run: func(act *action.Action) error { return nil },
}
}func newSubAction2() *action.Action {
return &action.Action{
Name: "sub-action2",
Executable: func(act *action.Action) bool {
// do something
return false
},
Run: func(act *action.Action) error { return nil },
}
}
```- `Executable`: whether is an executable action.
- `action.Execute()` will find the first executable action of the root action and execute it. If no executable action can be found, run the current action.## Documentation
You can find the docs at [go docs](https://pkg.go.dev/github.com/shipengqi/action).
## 🔋 JetBrains OS licenses
`action` had been being developed with **GoLand** under the **free JetBrains Open Source license(s)** granted by JetBrains s.r.o., hence I would like to express my thanks here.