cliutil

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 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 BinDir added in v0.4.5

func BinDir() string

BinDir get

func BinFile added in v0.4.5

func BinFile() string

BinFile get

func BuildLine added in v0.3.12

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.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 ReadFirstByte added in v0.3.12

func ReadFirstByte(question string) (byte, error)

ReadFirstByte read first byte char

Usage:

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

func ReadFirstRune added in v0.3.12

func ReadFirstRune(question string) (rune, error)

ReadFirstRune read first rune 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 := cliutil.ReadLine("")
ans, _ := cliutil.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

Usage: ret, err := cliutil.ShellExec("ls -al")

func String2OSArgs added in v0.3.12

func String2OSArgs(line string) []string

String2OSArgs parse input command line text to os.Args

func StringToOSArgs added in v0.3.8

func StringToOSArgs(line string) []string

StringToOSArgs parse input command line text to os.Args

func Workdir added in v0.4.5

func Workdir() string

Workdir get

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