congo

package module
v0.0.0-...-238c292 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2016 License: BSD-2-Clause Imports: 4 Imported by: 0

README

Congo

GoDoc Build Status

Congo is a dead simple console Go package that mimic net/http server API to provide a simple way to add an interactive console to your applications.

##Installation

go get github.com/uraimo/congo

##Usage

package main

import (
	"fmt"
	"github.com/uraimo/congo"
)


func readit(args []string){
	fmt.Println("ls called with args:", args)
}

func err(cmd string){
	fmt.Println("Unknown command", cmd)
}

func main(){
  t :=congo.NewTerm("localhost>")
  t.AddCommand("ls",readit)
  t.AddUnknownHandler(err)
  t.ListenUntilExit()
} 

TODO

  • Configurable exit command/s
  • History support
  • Configurable autocomplete

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Term

type Term struct {
	// contains filtered or unexported fields
}

Term struct representing a console manager

func NewTerm

func NewTerm(prompt string) *Term

NewTerm creates a new initialized Term struct

func (*Term) AddCommand

func (t *Term) AddCommand(name string, funct func([]string))

AddCommand adds a function handler for this command

func (*Term) AddUnknownHandler

func (t *Term) AddUnknownHandler(funct func(string))

AddUnknownHandler adds a function handler for unknown command

func (*Term) ListenUntilExit

func (t *Term) ListenUntilExit()

ListenUntilExit starts reading command until "exit" or "quit"

func (*Term) Prompt

func (t *Term) Prompt(prompt string)

Prompt set the prompt

func (*Term) RemoveCommand

func (t *Term) RemoveCommand(name string)

RemoveCommand removes a command/handler entry

Jump to

Keyboard shortcuts

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