cli

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ERR_READLINE        = errors.New("unable to create line reader")
	ERR_SIGINT_RECEIVED = errors.New("sigint received")
	ERR_INVALID_INPUT   = errors.New("no valid input specified")
	ERR_MIN_INPUT_LEN   = errors.New("longer input required")
	ERR_READ_BYTE       = errors.New("unabel to read input byte")
)

Functions

func PrintError

func PrintError(err error)

func PrintErrorMsg

func PrintErrorMsg(msg string)

Types

type Confirm

type Confirm struct {
	// Default value is false, meaning no
	Default bool
	// If kept as default false, the prompt is repeated until a valid anser is provided, otherwise if true, only asking once
	OnlyOnce bool
	// Prompt Text
	Prompt string
}

Basic Yes/No Dialog

func (Confirm) Ask

func (c Confirm) Ask() (string, error)

returns the string "yes" or "no" depending on user input, on error undefined

func (Confirm) AskBool

func (c Confirm) AskBool() (bool, error)

The returned bool is always true for yes and false for no, independent of the set default response

func (Confirm) AskBoolDefaultOnErr

func (c Confirm) AskBoolDefaultOnErr() bool

func (Confirm) AskBoolFalseOnErr

func (c Confirm) AskBoolFalseOnErr() bool

type Input

type Input struct {
	// default input to use when only pressing enter, shown in parenthesis after the prompt, if set
	Default string
	// input validation function
	Validate ValidateFunc
	// if kept as default false, the prompt is repeated until a valid anser is provided, otherwise if true, only asking once
	OnlyOnce bool
	// Prompt Text, colon with single trailing space will be appended as separator to user input
	Prompt string
	// add mandatory prefix for input
	ForcePrefix string
}

Input Dialog

func (Input) Get

func (i Input) Get() (string, error)

func (Input) GetEmptyOnErr

func (i Input) GetEmptyOnErr() string

type Op

type Op uint
const (
	Log Op = iota
	Update
)

type Progress

type Progress struct {
	// duration between loading char, default 100ms
	LoadingSpeed time.Duration
	// if set, show ASCII only loading symbol instead of unicode special char
	FallbackAscii bool
}

func (Progress) Spinners

func (p Progress) Spinners()

func (Progress) Start

func (p Progress) Start(initialTaskText string) chan<- TaskOperation

startLoadingTask starts a non-blocking loading task. It returns a channel to send task operations and a function to stop the loading.

type Select added in v0.3.4

type Select struct {
	Options  []string
	Defaults []bool
	Validate func(sel []bool) error
	Multiple bool
	OnlyOnce bool
	Prompt   string
}

func (Select) Get added in v0.3.4

func (s Select) Get() ([]bool, error)

func (Select) GetOne added in v0.3.4

func (s Select) GetOne() (string, error)

type TaskOperation

type TaskOperation struct {
	Log    string
	Update string
	Final  bool
}

type ValidateFunc

type ValidateFunc func(string) error

Jump to

Keyboard shortcuts

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