Documentation ¶
Overview ¶
Package cliutil provides some util functions for CLI
Index ¶
- func CurrentShell(onlyName bool) (path string)
- 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 HasShellEnv(shell string) bool
- func LineBuild(binFile string, args []string) string
- func ParseLine(line string) []string
- func QuickExec(cmdLine string, workDir ...string) (string, error)
- func ReadFirst(question string) (string, error)
- func ReadInput(question string) (string, error)
- func ReadLine(question string) (string, error)
- func ReadPassword(question ...string) string
- func ShellExec(cmdLine string, shells ...string) (string, error)
- func StringToOSArgs(line string) []string
- type LineBuilder
- type LineParser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentShell ¶
CurrentShell get current used shell env file. eg "/bin/zsh" "/bin/bash"
func ExecCommand ¶
ExecCommand alias of the ExecCmd()
func ReadLine ¶ added in v0.3.8
ReadLine read one line from user input. Usage:
in := ReadLine("") ans, _ := ReadLine("your name?")
func ReadPassword ¶ added in v0.3.8
ReadPassword from console terminal
func StringToOSArgs ¶ added in v0.3.8
StringToOSArgs parse input command line text to os.Args
Types ¶
type LineBuilder ¶ added in v0.3.10
type LineBuilder struct {
// contains filtered or unexported fields
}
LineBuilder build command line string. codes refer from strings.Builder
func NewLineBuilder ¶ added in v0.3.10
func NewLineBuilder(binFile string, args ...string) *LineBuilder
NewLineBuilder create
func (*LineBuilder) AddArg ¶ added in v0.3.10
func (b *LineBuilder) AddArg(arg string)
AddArg to builder
func (*LineBuilder) AddArgs ¶ added in v0.3.10
func (b *LineBuilder) AddArgs(args ...string)
AddArgs to builder
func (*LineBuilder) AddArray ¶ added in v0.3.10
func (b *LineBuilder) AddArray(args []string)
AddArray to builder
func (*LineBuilder) String ¶ added in v0.3.10
func (b *LineBuilder) String() string
String to command line string
func (*LineBuilder) WriteString ¶ added in v0.3.10
func (b *LineBuilder) WriteString(a string) (int, error)
WriteString arg string to the builder, will auto quote special string. refer strconv.Quote()
type LineParser ¶ added in v0.3.8
type LineParser struct { // Line the full input command line text // eg `kite top sub -a "the a message" --foo val1 --bar "val 2"` Line string // ParseEnv parse ENV var on the line. ParseEnv bool // contains filtered or unexported fields }
LineParser struct parse input command line to []string, such as cli os.Args
func NewLineParser ¶ added in v0.3.9
func NewLineParser(line string) *LineParser
NewLineParser create
func (*LineParser) AlsoEnvParse ¶ added in v0.3.9
func (p *LineParser) AlsoEnvParse() []string
AlsoEnvParse input command line text to os.Args, will parse ENV var
func (*LineParser) BinAndArgs ¶ added in v0.3.11
func (p *LineParser) BinAndArgs() (bin string, args []string)
BinAndArgs get binName and args
func (*LineParser) NewExecCmd ¶ added in v0.3.11
func (p *LineParser) NewExecCmd() *exec.Cmd
NewExecCmd quick create exec.Cmd by cmdline string
func (*LineParser) Parse ¶ added in v0.3.8
func (p *LineParser) Parse() []string
Parse input command line text to os.Args