icli

package module
v0.0.0-...-8bd9d45 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: MIT Imports: 6 Imported by: 0

README

icli

Interactive CLI library for Go

PkgGoDev

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommandList []Command

CommandList of all registered commands

Functions

func Active

func Active() bool

Active returns the current state of input-ability

func EnableHelp

func EnableHelp(about string)

EnableHelp registers help command with optional 'about' string at the top

func HandleCommand

func HandleCommand(str string)

HandleCommand parses string for command/args and calls callback if command exists

func Println

func Println(args ...interface{})

Println is a standin replacement for fmt.Println

func Quit

func Quit()

Quit the command loop and clean up

func RePrintln

func RePrintln(args ...interface{})

RePrintln reprints the last line, useful for updating progress

func ReadLine

func ReadLine(text string, def string) string

ReadLine waits for user input and returns as string. Temporarily changes prompt text and returns default value on empty input

func Register

func Register(cmd Command) error

Register a command to the interactive cli

func SetActive

func SetActive(b bool)

SetActive toggles input-ability

func SetText

func SetText(str string)

SetText sets the prompt's text (before the >)

func Start

func Start(enableAutocomplete bool) error

Start the blocking command loop. You can spawn this in a new goroutine and handle the busy wait yourself, but be aware that this may eat the user's first Ctrl+C and require a second to terminate. Recommended that you put this as the last thing in your main()

func Text

func Text() string

Text returns the prompt's current text

Types

type Command

type Command struct {
	Aliases  []string     // one or many aliases this command can be called by
	Callback func(string) // callback function, takes the inputted arguments as a string
	Help     string       // for help command, first line is used when listing all commands
	Hidden   bool         // hides command from help list
}

Command data for a single command

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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