diff --git a/README.md b/README.md index 5a7fa9c..87c4d37 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,10 @@ A kitchen sink of Go tools that I've found useful. Uses only the standard librar - [super lightweight http server framework](web) - [exponential backoff retry](retry.go) -- [working with json](json.go) +- [working with JSON](json.go) - [working with the file system](fs.go) - [working with slices](slice.go) +- [working with CLIs](cli.go) ### example usage diff --git a/app b/app index 742a813..a658b53 100644 Binary files a/app and b/app differ diff --git a/cli.go b/cli.go index 2b715df..ec2b8da 100644 --- a/cli.go +++ b/cli.go @@ -2,9 +2,20 @@ package gotoolbox import ( "bytes" + "os" "os/exec" ) +//GetEnvWithDefault returns the value of an enviornment variable +//or a default value if the environment variables is not set +func GetEnvWithDefault(key, defaultValue string) string { + result := os.Getenv(key) + if result == "" { + return defaultValue + } + return result +} + //ExecCmd executes a command and waits func ExecCmd(cmd *exec.Cmd) error {