turban

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

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

Go to latest
Published: Sep 16, 2016 License: GPL-3.0 Imports: 11 Imported by: 0

README

Turban Shell

GoDoc Go Report Card

A simple shell experience.

Turban Preview

Turban Application

There is a turban shell application available in the cmd directory. It reads a TURBAN.toml file and provides a simple shell.

	go get -u github.com/desertbit/turban
	go install github.com/desertbit/turban/cmd/turban
	turban -p "prompt text" -d "path to directory"

Library Sample

package main

import (
	"fmt"

	"github.com/desertbit/turban"
)

func main() {
	turban.SetPrompt("TURBAN » ")
	turban.SetHelpHeader("TURBAN - A simple shell experience")
	turban.SetPrintASCIIArtFunc(printASCIIArt)

	turban.AddCommand("foo", &turban.Command{
		Help:  "Print foo help text",
		Usage: "foo [BAR]",
		Run: func(args []string) error {
			// ...
			return nil
		},
	})

	turban.Run(true)
}

func printASCIIArt() {
	fmt.Println("____ _ _  ___  ___   __  _ _ ")
	fmt.Println(" ))  ))`) ))_) ))_) /_`) )\\`)")
	fmt.Println("((  ((_( ((`\\ ((__)(( ( ((`( ")
	fmt.Println("")
}

Documentation

Overview

Package turban offers a simple shell experience.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidUsage when returned by the Run Command function,
	// then usage is printed.
	ErrInvalidUsage = errors.New("invalid usage")
)

Functions

func AddCommand

func AddCommand(key string, cmd *Command)

AddCommand register a new shell command.

func AskForConfirmation

func AskForConfirmation(s string) bool

AskForConfirmation asks the user for confirmation. A user must type in "yes" or "no" and then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as confirmations. If the input is not recognized, it will ask again. The function does not return until it gets a valid response from the user.

func Run

func Run(withColor bool) error

Run the shell.

func SetHelpHeader

func SetHelpHeader(h string)

SetHelpHeader sets the header displayed in the help.

func SetPrintASCIIArtFunc

func SetPrintASCIIArtFunc(f func())

SetPrintASCIIArtFunc sets the function which is called when the ASCII art logo should be printed.

func SetPrompt

func SetPrompt(p string)

SetPrompt sets the prompt string.

func Stop

func Stop()

Stop the shell run loop.

Types

type Command

type Command struct {
	Help  string
	Usage string
	Run   RunFunc

	PrefixCompleter *readline.PrefixCompleter
}

A Command specifies a turban shell command. PrefixCompleter is optional and will be set to a default if not set.

type RunFunc

type RunFunc func(args []string) error

RunFunc specifies the function which is run during a command.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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