comfunc

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v any) bool

Bool try to convert type to bool

func Cmdline

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

Cmdline build

func CurrentShell

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

func Environ() map[string]string

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

func ExecCmd

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

ExecCmd an command and return output.

Usage:

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

func ExpandPath

func ExpandPath(pathStr string) string

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

func FormatTplAndArgs

func FormatTplAndArgs(fmtAndArgs []any) string

FormatTplAndArgs message

func HasShellEnv

func HasShellEnv(shell string) bool

HasShellEnv has shell env check.

Usage:

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

func ParseEnvVar

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

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

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

func StrToBool

func StrToBool(s string) (bool, error)

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

func ToBool

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