comfunc

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool added in v0.5.12

func Bool(v any) bool

Bool try to convert type to bool

func Cmdline added in v0.5.11

func Cmdline(args []string, binName ...string) string

Cmdline build

func CurrentShell added in v0.5.3

func CurrentShell(onlyName bool) (path string)

CurrentShell get current used shell env file.

eg "/bin/zsh" "/bin/bash". if onlyName=true, will return "zsh", "bash"

func Environ added in v0.5.11

func Environ() map[string]string

Environ like os.Environ, but will returns key-value map[string]string data.

func ExecCmd added in v0.5.3

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

ExecCmd an command and return output.

Usage:

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

func ExpandPath added in v0.5.3

func ExpandPath(pathStr string) string

ExpandPath will parse first `~` as user home dir path.

func HasShellEnv added in v0.5.3

func HasShellEnv(shell string) bool

HasShellEnv has shell env check.

Usage:

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

func ParseEnvVar added in v0.5.11

func ParseEnvVar(val string, getFn func(string) string) (newVal string)

ParseEnvVar parse ENV var value from input string, support default value.

Format:

${var_name}            Only var name
${var_name | default}  With default value

Usage:

comfunc.ParseEnvVar("${ APP_NAME }")
comfunc.ParseEnvVar("${ APP_ENV | dev }")

func ShellExec added in v0.5.3

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

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

func StrToBool added in v0.5.11

func StrToBool(s string) (bool, error)

StrToBool parse string to bool. like strconv.ParseBool()

func ToBool added in v0.5.11

func ToBool(v any) (bool, error)

ToBool try to convert type to bool

Types

This section is empty.

Jump to

Keyboard shortcuts

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