cli

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 8 Imported by: 12

README

cli

A library with useful utilities for writing CLI applications.

License

MIT License

Copyright (c) 2022 Julian Hofmann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = errors.New("canceled")

ErrCanceled indicates that the user has interrupted the programm, e.g. by using Ctrl + C.

Functions

func BeginLoading

func BeginLoading(format string, a ...any)

func BeginProgressBar

func BeginProgressBar(format string, a ...any)

func CancelLoading

func CancelLoading()

func CancelProgressBar

func CancelProgressBar()

func Clear added in v0.2.1

func Clear()

func Error

func Error(format string, a ...any)

func FinishLoading

func FinishLoading()

func FinishProgressBar

func FinishProgressBar()

func Input

func Input(prompt string, validators ...Validator) (string, error)

Input ask the user to input a line of text.

func InputOptional added in v0.2.2

func InputOptional(prompt string, validators ...Validator) (string, error)

InputOptional ask the user to input a line of text. Not required.

func MultiSelect added in v0.2.0

func MultiSelect(msg string, options []string, selected []int) ([]bool, error)

MultiSelect asks the user to select an arbitrary amount of options. It returns a boolean slice of length options with the chosen indices set to true.

func Print

func Print(format string, a ...any)

func PrintColor

func PrintColor(color Color, format string, a ...any)

func Select

func Select(msg string, options []string) (int, error)

Select asks the user to select on option. It returns the index of the chosen option.

func SelectString

func SelectString(msg string, displayOptions []string, options []string) (string, error)

SelectString asks the user to select on option. It returns the entry in options with the chosen index. It panics if the length of displayOptions differs from the length of options.

func Success

func Success(format string, a ...any)

func UpdateProgressBar

func UpdateProgressBar(progress float64)

func Warn

func Warn(format string, a ...any)

func YesNo

func YesNo(question string, defaultValue bool) (yes bool, err error)

YesNo asks the user a yes/no question.

Types

type Color

type Color string
const (
	Reset       Color = "\x1b[0m"
	Black       Color = "\x1b[30m"
	Red         Color = "\x1b[31m"
	Green       Color = "\x1b[32m"
	Yellow      Color = "\x1b[33m"
	Blue        Color = "\x1b[34m"
	Magenta     Color = "\x1b[35m"
	Cyan        Color = "\x1b[36m"
	White       Color = "\x1b[37m"
	BlackBold   Color = "\x1b[1;30m"
	RedBold     Color = "\x1b[1;31m"
	GreenBold   Color = "\x1b[1;32m"
	YellowBold  Color = "\x1b[1;33m"
	BlueBold    Color = "\x1b[1;34m"
	MagentaBold Color = "\x1b[1;35m"
	CyanBold    Color = "\x1b[1;36m"
	WhiteBold   Color = "\x1b[1;37m"
)

type Validator

type Validator func(input interface{}) error

func MaxLength

func MaxLength(n int) Validator

func MinLength

func MinLength(n int) Validator

func Regexp

func Regexp(regexp *regexp.Regexp, errorMsg string) Validator

Jump to

Keyboard shortcuts

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