refactor(internal/client): use flags instead of env vars

This commit is contained in:
Dustin Stiles 2025-03-24 13:57:00 -04:00
parent f8c32151f6
commit 19e9674f40
Signed by: duwstiles
GPG Key ID: BCD9912EC231FC87

View File

@ -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