Documentation
¶
Index ¶
- func Bool(v any) bool
- func Cmdline(args []string, binName ...string) string
- func CurrentShell(onlyName bool) (binPath string)
- func Environ() map[string]string
- func ExecCmd(binName string, args []string, workDir ...string) (string, error)
- func ExpandHome(pathStr string) string
- func FormatTplAndArgs(fmtAndArgs []any) string
- func HasShellEnv(shell string) bool
- func IsDuration(s string) bool
- func ParseEnvVar(val string, getFn func(string) string) (newVal string)
- func ShellExec(cmdLine string, shells ...string) (string, error)
- func StrToBool(s string) (bool, error)
- func ToBool(v any) (bool, error)
- func ToDuration(s string) (time.Duration, error)
- func Workdir() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentShell ¶ added in v0.5.3
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
Environ like os.Environ, but will returns key-value map[string]string data.
func ExecCmd ¶ added in v0.5.3
ExecCmd an command and return output.
Usage:
ExecCmd("ls", []string{"-al"})
func ExpandHome ¶ added in v0.6.8
ExpandHome will parse first `~` as user home dir path.
func FormatTplAndArgs ¶ added in v0.6.2
FormatTplAndArgs message
func HasShellEnv ¶ added in v0.5.3
HasShellEnv has shell env check.
Usage:
HasShellEnv("sh")
HasShellEnv("bash")
func IsDuration ¶ added in v0.6.9
IsDuration check the string is a duration string.
func ParseEnvVar ¶ added in v0.5.11
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 ToDuration ¶ added in v0.6.9
ToDuration parses a duration string. such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
Diff of time.ParseDuration:
- support extend unit d, w at the end of string. such as "1d", "2w".
- support long string unit at end. such as "1hour", "2hours", "3minutes", "4mins", "5days", "1weeks".
If the string is not a valid duration string, it will return an error.
Types ¶
This section is empty.