Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/margostino/griffin
Shell generator built on top of GO Prompt (a library for building powerful interactive prompts) to bind commands and actions dynamically and focus on the action handler.
https://github.com/margostino/griffin
cli command-line shell terminal
Last synced: 17 days ago
JSON representation
Shell generator built on top of GO Prompt (a library for building powerful interactive prompts) to bind commands and actions dynamically and focus on the action handler.
- Host: GitHub
- URL: https://github.com/margostino/griffin
- Owner: margostino
- License: mit
- Created: 2021-10-09T16:39:42.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-11-30T18:14:54.000Z (about 2 years ago)
- Last Synced: 2024-11-10T09:13:57.123Z (3 months ago)
- Topics: cli, command-line, shell, terminal
- Language: Go
- Homepage: https://margostino.com/
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Griffin
[![Go Report Card](https://goreportcard.com/badge/github.com/margostino/griffin)](https://goreportcard.com/report/github.com/margostino/griffin)
![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)
[![GoDoc](https://godoc.org/github.com/margostino/griffin?status.svg)](https://godoc.org/github.com/margostino/griffin)
![tests](https://github.com/margostino/griffin/workflows/tests/badge.svg)Shell generator built on top of [GO Prompt](https://github.com/c-bata/go-prompt) (a library for building powerful
interactive prompts). Griffin allows to bind command and actions by configuration in order to reduce boilerplate code
and let developer focus on the action handling.```go
package mainimport (
"fmt"
"github.com/margostino/griffin/pkg/griffin"
)var Actions = map[string]func(){
"ExecuteDoSomething": ExecuteDoSomething,
}var InputActions = map[string]func([]string){
"ExecuteDoSomethingWithInput": ExecuteDoSomethingWithInput,
}func ExecuteDoSomething() {
fmt.Println("do something")
}func ExecuteSelectSomething(args []string) {
fmt.Println("select something %s", args[0])
}func main() {
powershell := griffin.New().
SetActions(Actions).
SetActionsStrings(InputActions).
LoadConfiguration("commands.yml")
powershell.Start()
}
```### Configuration
Example:
```yaml
commands:
- id: select something
description: "Select something amazing"
action: ExecuteDoSomething
- id: select input
args: 1
description: "Select input"
pattern: "^select something [a-z-A-Z]+$"
action: ExecuteSelectSomething
```### Commands
A shell can be created with Actions and Commands. A command might be: `run job`.
### Actions
An action is a function name without params: `ExecuteSomething()` or a function name with string
params: `ExecuteSomething(name string)`. Currently, only string params are supported.### Configuration
Configuration might be loaded by YML file (see [example](./example/config/commands.yml)) or sending a list
of `CommandConfiguration`:```go
type CommandConfiguration struct {
Id string `yaml:"id"`
Description string `yaml:"description"`
Args int `yaml:"args"`
Action string `yaml:"action"`
Pattern string `yaml:"pattern"`
}
````ID`: the command keys to trigger an action.
Example: `run job`, `help`, `show users``Description`: short description of the command and action. This will be visible in as prompt suggestion.
`Args`: amount of parameters that the action needs to be executed. Default `0`
`Action`: name of the function handler to serve the command ID.
`Pattern`: if `Args > 1` a regex pattern is used to match the command with action.