utils

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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(cmdStr string, dirAndShell ...string) (string, error)

ExecCommand alias of the ShellExec

func GetCurShell

func GetCurShell(onlyName bool) string

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

func GetKeyMaxLen

func GetKeyMaxLen(kv map[string]interface{}, defLen int) (max int)

GetKeyMaxLen get key max length of the map usage:

utils.GetKeyMaxLen(map[string]string{"k1":"v1", "key2": "v2"}, 0)

func GetScreenSize

func GetScreenSize() (w int, h int)

GetScreenSize for current console terminal

func Go

func Go(f func() error) chan error

Go is a basic promise implementation: it wraps calls a function in a goroutine and returns a channel which will later return the function's return value. from beego/bee

func HasShellEnv added in v1.1.2

func HasShellEnv(shell string) bool

HasShellEnv check usage:

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

func IsConsole

func IsConsole(out io.Writer) bool

IsConsole 判断 w 是否为 stderr、stdout、stdin 三者之一

func IsLinux

func IsLinux() bool

IsLinux system env

func IsMSys

func IsMSys() bool

IsMSys msys(MINGW64) 环境,不一定支持颜色

func IsMac

func IsMac() bool

IsMac system env

func IsSupport256Color

func IsSupport256Color() bool

IsSupport256Color for current CLI

func IsSupportColor

func IsSupportColor() bool

IsSupportColor check console is support color. supported: linux, mac, or windows's ConEmu, Cmder, putty, git-bash.exe not support: windows cmd, powerShell

func IsWin

func IsWin() bool

IsWin system env

func LcFirst

func LcFirst(s string) string

LcFirst char for given string

func RenderTemplate

func RenderTemplate(input string, data interface{}, isFile ...bool) string

RenderTemplate render text template with data

func ShellExec added in v1.1.2

func ShellExec(cmdStr string, dirAndShell ...string) (string, error)

ShellExec exec a CLI command by shell and return output. usage:

utils.ShellExec("ls -al")
utils.ShellExec("ls -al", "/usr/lib")
utils.ShellExec("ls -al", "/usr/lib", "/bin/zsh")

func UcFirst

func UcFirst(s string) string

UcFirst upper first char

Types

This section is empty.

Jump to

Keyboard shortcuts

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