mirror of
https://git.numenor-labs.us/dsfx.git
synced 2025-05-04 18:10:34 +00:00
refactor(internal/client): use flags instead of env vars
This commit is contained in:
parent
f8c32151f6
commit
19e9674f40
@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"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.
|
// Client represents the client application for dsfxctl.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
// resources
|
// resources
|
||||||
@ -76,7 +63,16 @@ type Client struct {
|
|||||||
// New creates a new Client instance with the provided disk, system, and
|
// New creates a new Client instance with the provided disk, system, and
|
||||||
// configuration.
|
// configuration.
|
||||||
func New(disk disk.Disk, system system.System) *Client {
|
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{
|
return &Client{
|
||||||
// resources
|
// resources
|
||||||
|
Loading…
x
Reference in New Issue
Block a user