Documentation ¶
Overview ¶
Package cliutil provides some util functions for CLI
Index ¶
- Variables
- func BinDir() string
- func BinFile() string
- func BinName() string
- func Bluef(format string, a ...any)
- func Blueln(a ...any)
- func Bluep(a ...any)
- func BuildLine(binFile string, args []string) string
- func BuildOptionHelpName(names []string) string
- func ByteIsYes(ans byte) bool
- func Confirm(tip string, defVal ...bool) bool
- func CurrentShell(onlyName bool) (path string)
- func Cyanf(format string, a ...any)
- func Cyanln(a ...any)
- func Cyanp(a ...any)
- func Errorf(format string, a ...any)
- func Errorln(a ...any)
- func Errorp(a ...any)
- func ExecCmd(binName string, args []string, workDir ...string) (string, error)
- func ExecCommand(binName string, args []string, workDir ...string) (string, error)
- func ExecLine(cmdLine string, workDir ...string) (string, error)
- func GetTermSize(refresh ...bool) (w int, h int)
- func Grayf(format string, a ...any)
- func Grayln(a ...any)
- func Grayp(a ...any)
- func Greenf(format string, a ...any)
- func Greenln(a ...any)
- func Greenp(a ...any)
- func HasShellEnv(shell string) bool
- func Infof(format string, a ...any)
- func Infoln(a ...any)
- func Infop(a ...any)
- func InputIsYes(ans string) bool
- func LineBuild(binFile string, args []string) string
- func Magentaf(format string, a ...any)
- func Magentaln(a ...any)
- func Magentap(a ...any)
- func OutputLines(output string) []string
- func ParseLine(line string) []string
- func QuickExec(cmdLine string, workDir ...string) (string, error)
- func ReadAsBool(tip string, defVal bool) bool
- func ReadFirst(question string) (string, error)
- func ReadFirstByte(question string) (byte, error)
- func ReadFirstRune(question string) (rune, error)
- func ReadInput(question string) (string, error)
- func ReadLine(question string) (string, error)
- func ReadPassword(question ...string) string
- func Redf(format string, a ...any)
- func Redln(a ...any)
- func Redp(a ...any)
- func ShellExec(cmdLine string, shells ...string) (string, error)
- func ShellQuote(s string) string
- func SplitMulti(ss []string, sep string) []string
- func String2OSArgs(line string) []string
- func StringToOSArgs(line string) []string
- func Successf(format string, a ...any)
- func Successln(a ...any)
- func Successp(a ...any)
- func Warnf(format string, a ...any)
- func Warnln(a ...any)
- func Warnp(a ...any)
- func Workdir() string
- func Yellowf(format string, a ...any)
- func Yellowln(a ...any)
- func Yellowp(a ...any)
Constants ¶
This section is empty.
Variables ¶
var ( // Input global input stream Input io.Reader = os.Stdin // Output global output stream Output io.Writer = os.Stdout )
the global input output stream
var FirstLine = strutil.FirstLine
FirstLine from command output
Deprecated: please use strutil.FirstLine
Functions ¶
func BuildOptionHelpName ¶ added in v0.5.5
BuildOptionHelpName for render flag help
func CurrentShell ¶
CurrentShell get current used shell env file. eg "/bin/zsh" "/bin/bash"
func ExecCommand ¶
ExecCommand alias of the ExecCmd()
func GetTermSize ¶ added in v0.6.0
GetTermSize for current console terminal.
func InputIsYes ¶ added in v0.6.0
InputIsYes answer: yes, y, Yes, Y
func Magentaln ¶ added in v0.5.3
func Magentaln(a ...any)
Magentaln print message line with magenta color
func OutputLines ¶ added in v0.5.11
OutputLines split output to lines
func ReadAsBool ¶ added in v0.6.9
ReadAsBool check user inputted answer is right
Usage:
ok := ReadAsBool("are you OK? [y/N]", false)
func ReadFirst ¶ added in v0.3.8
ReadFirst read first char
Usage:
ans, _ := cliutil.ReadFirst("continue?[y/n] ")
func ReadFirstByte ¶ added in v0.3.12
ReadFirstByte read first byte char
Usage:
ans, _ := cliutil.ReadFirstByte("continue?[y/n] ")
func ReadFirstRune ¶ added in v0.3.12
ReadFirstRune read first rune char
func ReadLine ¶ added in v0.3.8
ReadLine read one line from user input.
Usage:
in := cliutil.ReadLine("") ans, _ := cliutil.ReadLine("your name?")
func ReadPassword ¶ added in v0.3.8
ReadPassword from console terminal
func ShellQuote ¶ added in v0.5.9
ShellQuote quote a string on contains ', ", SPACE
func SplitMulti ¶ added in v0.6.13
SplitMulti split multi string by sep string.
func String2OSArgs ¶ added in v0.3.12
String2OSArgs parse input command line text to os.Args
func StringToOSArgs ¶ added in v0.3.8
StringToOSArgs parse input command line text to os.Args
func Successln ¶ added in v0.5.6
func Successln(a ...any)
Successln print message with success style
Types ¶
This section is empty.