From 19e9674f4053a6bf9f2b64d9763613dae7761fb0 Mon Sep 17 00:00:00 2001 From: Dustin Stiles Date: Mon, 24 Mar 2025 13:57:00 -0400 Subject: [PATCH] refactor(internal/client): use flags instead of env vars --- internal/client/client.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/internal/client/client.go b/internal/client/client.go index 28ce7bd..fea59f3 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -6,6 +6,7 @@ import ( "crypto/rand" "encoding/base64" "errors" + "flag" "fmt" "io" "log/slog" @@ -48,20 +49,6 @@ func (c Conf) SlogLevel() slog.Level { } } -func loadConfigFromSystem(sys system.System) Conf { - var c Conf - - c.ConfigDir = sys.GetEnv("DSFXCTL_CONFIG_DIR") - if c.ConfigDir == "" { - c.ConfigDir = DefaultConfigDir - } - - // defaults are handled by Conf.SlogLevel. - c.LogLevel = sys.GetEnv("DSFXCTL_LOG_LEVEL") - - return c -} - // Client represents the client application for dsfxctl. type Client struct { // resources @@ -76,7 +63,16 @@ type Client struct { // New creates a new Client instance with the provided disk, system, and // configuration. func New(disk disk.Disk, system system.System) *Client { - conf := loadConfigFromSystem(system) + flagConfig := flag.String("configDir", "/etc/dsfxctl", "Path to the configuration directory") + flagLogLevel := flag.String("logLevel", "info", "The log level (debug, info, warn, error)") + + if !flag.Parsed() { + flag.Parse() + } + conf := Conf{ + LogLevel: *flagLogLevel, + ConfigDir: *flagConfig, + } return &Client{ // resources