cliutil

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cliutil provides some util functions for CLI

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildLine added in v0.4.1

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

BuildLine build command line string by given args.

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.4.1

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.4.1

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

LineBuild build command line string by given args.

func ParseLine added in v0.4.1

func ParseLine(line string) []string

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

func QuickExec added in v0.4.1

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

QuickExec quick exec an simple command line

func ReadFirst added in v0.4.1

func ReadFirst(question string) (string, error)

ReadFirst read first char

func ReadFirstByte added in v0.4.1

func ReadFirstByte(question string) (byte, error)

ReadFirstByte read first byte char

Usage:

ans, _ := ReadFirstByte("continue?[y/n] ")

func ReadFirstRune added in v0.4.1

func ReadFirstRune(question string) (rune, error)

ReadFirstRune read first rune char

func ReadInput added in v0.4.1

func ReadInput(question string) (string, error)

ReadInput read user input form Stdin

func ReadLine added in v0.4.1

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.4.1

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 String2OSArgs added in v0.4.1

func String2OSArgs(line string) []string

String2OSArgs parse input command line text to os.Args

func StringToOSArgs added in v0.4.1

func StringToOSArgs(line string) []string

StringToOSArgs parse input command line text to os.Args

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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