Skip to content

Commit

Permalink
Add env var check for verbose and supporting function
Browse files Browse the repository at this point in the history
  • Loading branch information
bbriggs committed Jan 23, 2024
1 parent 4d02ae8 commit cb2d2e4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"os"
"strings"
)

// This file contains environnement variables parsing related methods,
Expand Down Expand Up @@ -35,6 +36,10 @@ func parseEnv() {
if !isFlagSet("ruser") {
*redisUser = parseStringFromEnv("BYTEBOT_RUSER", "")
}

if !isFlagSet("verbose") {
*verbose = parseBoolFromEnv("BYTEBOT_VERBOSE", false)
}
}

// Parses a string from an env variable and returns it.
Expand All @@ -46,6 +51,15 @@ func parseStringFromEnv(varName, defaultVal string) string {
return defaultVal
}

// Parses a boolean from an env variable and returns it.
func parseBoolFromEnv(varName string, defaultVal bool) bool {
val, set := os.LookupEnv(varName)
if set {
return strings.ToLower(val) == "true"
}
return false
}

// This is used to check if a flag was set
// Must be called after flag.Parse()
func isFlagSet(name string) bool {
Expand Down

0 comments on commit cb2d2e4

Please sign in to comment.