gocli

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

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

Go to latest
Published: May 28, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MinimumNArgs

func MinimumNArgs(args []string, n int) error

Types

type AutoCompleter

type AutoCompleter interface {
	// Readline will pass the whole line and current offset to it
	// Completer need to pass all the candidates, and how long they shared the same characters in line
	// Example:
	//   [go, git, git-shell, grep]
	//   Do("g", 1) => ["o", "it", "it-shell", "rep"], 1
	//   Do("gi", 2) => ["t", "t-shell"], 2
	//   Do("git", 3) => ["", "-shell"], 3
	Do(line []rune, pos int) (newLine [][]rune, length int)
}

type Cli

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

func New

func New(options ...Option) *Cli

func (*Cli) Commands

func (c *Cli) Commands() []Command

func (*Cli) Config

func (c *Cli) Config() *Config

func (*Cli) ParseCommands

func (c *Cli) ParseCommands(commander interface{}) error

func (*Cli) PostRun

func (c *Cli) PostRun(postRun func(args []string))

func (*Cli) PreRun

func (c *Cli) PreRun(preRun func(args []string))

func (*Cli) Run

func (c *Cli) Run(name string, app interface{}) error

func (*Cli) SetCommands

func (c *Cli) SetCommands(commands []Command)

func (*Cli) SetConfig

func (c *Cli) SetConfig(config *Config)

type Command

type Command struct {
	Name        string
	SubCommands []Command
}

type Config

type Config struct {
	Cfg      *readline.Config
	Commands []Command
}

type Option

type Option func(config *Config) error

func WithAutoComplete

func WithAutoComplete(autoComplete AutoCompleter) Option

WithAutoComplete AutoCompleter will called once user press TAB

func WithCommands

func WithCommands(commands []Command) Option

func WithConfig

func WithConfig(config *Config) Option

func WithDisableAutoSaveHistory

func WithDisableAutoSaveHistory(disableAutoSaveHistory bool) Option

func WithEOFPrompt

func WithEOFPrompt(EOFPrompt string) Option

func WithHistoryFile

func WithHistoryFile(historyFile string) Option

func WithHistoryLimit

func WithHistoryLimit(historyLimit int) Option

WithHistoryLimit specify the max length of historys, it's 500 by default, set it to -1 to disable history

func WithHistorySearchFold

func WithHistorySearchFold(historySearchFold bool) Option

WithHistorySearchFold enable case-insensitive history searching

func WithInterruptPrompt

func WithInterruptPrompt(interruptPrompt string) Option

func WithPrompt

func WithPrompt(prompt string) Option

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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