gorpl

package module
v0.0.0-...-a452233 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2018 License: MIT Imports: 5 Imported by: 1

README

gorpl Go Report Card

A simple to use wrapper for readline.

Features

  • Simple API
  • Register callback functions

Usage

go get github.com/xandout/gorpl


package main

import (
	"fmt"
	"os"

	"github.com/xandout/gorpl"

	"github.com/xandout/gorpl/action"
)

var mode = "table"

func main() {

	exitAction := action.New("exit", func(args ...interface{}) (interface{}, error) {
		fmt.Println("Bye!")
		os.Exit(0)
		return nil, nil
	})
	modeAction := action.New("mode", func(args ...interface{}) (interface{}, error) {
		if len(args) == 0 {
			fmt.Printf("Current mode is %s\n", mode)
		}
		return "", nil
	})
	csvAction := action.New("csv", func(args ...interface{}) (interface{}, error) {
		mode = "csv"
		fmt.Printf("Mode set to %s\n", mode)

		return "", nil
	})
	tableAction := action.New("table", func(args ...interface{}) (interface{}, error) {
		mode = "table"
		fmt.Printf("Mode set to %s\n", mode)
		return "", nil
	})
	csvChild := action.New("csvChild", func(args ...interface{}) (interface{}, error) {
		fmt.Println("csvChild!")
		fmt.Println(args)
		return nil, nil
	})
	csvChildChild := action.New("csvChildChild", func(args ...interface{}) (interface{}, error) {
		fmt.Println("csvChildChild!")
		fmt.Println(args)
		return nil, nil
	})
	csvChild.AddChild(csvChildChild)
	csvAction.AddChild(csvChild)

	modeAction.AddChild(csvAction)
	modeAction.AddChild(tableAction)

	f := gorpl.New(";")
	f.AddAction(*modeAction)
	f.AddAction(*exitAction)
	f.Start()
}


TODO
  • Enable nested completion

  • Enable dynamic autocompletion

  • Have to register children before parents....need to clean up the API

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repl

type Repl struct {
	RL         *readline.Instance
	Actions    []action.Action
	Default    action.Action
	Prefix     string
	Terminator string
}

Repl houses all of our config data

func New

func New(term string) Repl

New sets up the Repl

func (*Repl) AddAction

func (r *Repl) AddAction(action action.Action)

AddAction registers a named function, Action

func (*Repl) Start

func (r *Repl) Start() error

Start runs the Repl as configured

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL