Skip to content

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.

License

Notifications You must be signed in to change notification settings

margostino/griffin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Griffin

Go Report Card Software License GoDoc tests

Shell generator built on top of 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.

package main

import (
	"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:

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) or sending a list of CommandConfiguration:

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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published