cliutil

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 9 Imported by: 24

Documentation

Overview

Package cliutil provides some util functions for CLI

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentShell

func CurrentShell(onlyName bool) (path string)

CurrentShell get current used shell env file. eg "/bin/zsh" "/bin/bash"

func ExecCmd

func ExecCmd(binName string, args []string, workDir ...string) (string, error)

ExecCmd a CLI bin file and return output. Usage:

ExecCmd("ls", []string{"-al"})

func ExecCommand

func ExecCommand(binName string, args []string, workDir ...string) (string, error)

ExecCommand alias of the ExecCmd()

func ExecLine added in v0.3.11

func ExecLine(cmdLine string, workDir ...string) (string, error)

ExecLine quick exec an command line string

func HasShellEnv

func HasShellEnv(shell string) bool

HasShellEnv has shell env check. Usage:

HasShellEnv("sh")
HasShellEnv("bash")

func LineBuild added in v0.3.10

func LineBuild(binFile string, args []string) string

LineBuild build command line string by given args.

func ParseLine added in v0.3.8

func ParseLine(line string) []string

ParseLine input command line text. alias of the StringToOSArgs()

func QuickExec added in v0.1.4

func QuickExec(cmdLine string, workDir ...string) (string, error)

QuickExec quick exec an simple command line

func ReadFirst added in v0.3.8

func ReadFirst(question string) (string, error)

ReadFirst read first char

func ReadInput added in v0.3.8

func ReadInput(question string) (string, error)

ReadInput read user input form Stdin

func ReadLine added in v0.3.8

func ReadLine(question string) (string, error)

ReadLine read one line from user input. Usage:

in := ReadLine("")
ans, _ := ReadLine("your name?")

func ReadPassword added in v0.3.8

func ReadPassword(question ...string) string

ReadPassword from console terminal

func ShellExec

func ShellExec(cmdLine string, shells ...string) (string, error)

ShellExec exec command by shell cmdStr eg. "ls -al"

func StringToOSArgs added in v0.3.8

func StringToOSArgs(line string) []string

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) Len added in v0.3.10

func (b *LineBuilder) Len() int

Len of the builder

func (*LineBuilder) Reset added in v0.3.10

func (b *LineBuilder) Reset()

Reset 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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