updated to use bun and updated hws modules.
This commit is contained in:
87
internal/config/envprint.go
Normal file
87
internal/config/envprint.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PrintEnvVars writes all environment variables and their documentation to the provided writer
|
||||
func PrintEnvVars(w io.Writer) error {
|
||||
envVars := GetAllEnvVars()
|
||||
|
||||
// Find the longest name for alignment
|
||||
maxNameLen := 0
|
||||
for _, ev := range envVars {
|
||||
if len(ev.Name) > maxNameLen {
|
||||
maxNameLen = len(ev.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// Print header
|
||||
fmt.Fprintln(w, "Environment Variables")
|
||||
fmt.Fprintln(w, strings.Repeat("=", 80))
|
||||
fmt.Fprintln(w)
|
||||
|
||||
// Group by prefix
|
||||
groups := map[string][]EnvVar{
|
||||
"DB_": {},
|
||||
"HWS_": {},
|
||||
"HWSAUTH_": {},
|
||||
"TMDB_": {},
|
||||
"LOG_": {},
|
||||
}
|
||||
|
||||
for _, ev := range envVars {
|
||||
assigned := false
|
||||
for prefix := range groups {
|
||||
if strings.HasPrefix(ev.Name, prefix) {
|
||||
groups[prefix] = append(groups[prefix], ev)
|
||||
assigned = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !assigned {
|
||||
// Handle ungrouped vars
|
||||
if _, ok := groups["OTHER"]; !ok {
|
||||
groups["OTHER"] = []EnvVar{}
|
||||
}
|
||||
groups["OTHER"] = append(groups["OTHER"], ev)
|
||||
}
|
||||
}
|
||||
|
||||
// Print each group
|
||||
groupOrder := []string{"DB_", "HWS_", "HWSAUTH_", "TMDB_", "LOG_", "OTHER"}
|
||||
groupTitles := map[string]string{
|
||||
"DB_": "Database Configuration",
|
||||
"HWS_": "HTTP Web Server Configuration",
|
||||
"HWSAUTH_": "Authentication Configuration",
|
||||
"TMDB_": "TMDB API Configuration",
|
||||
"LOG_": "Logging Configuration",
|
||||
"OTHER": "Other Configuration",
|
||||
}
|
||||
|
||||
for _, prefix := range groupOrder {
|
||||
vars, ok := groups[prefix]
|
||||
if !ok || len(vars) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "%s\n", groupTitles[prefix])
|
||||
fmt.Fprintln(w, strings.Repeat("-", len(groupTitles[prefix])))
|
||||
|
||||
for _, ev := range vars {
|
||||
padding := strings.Repeat(" ", maxNameLen-len(ev.Name))
|
||||
if ev.Required {
|
||||
fmt.Fprintf(w, " %s%s : %s (required)\n", ev.Name, padding, ev.Description)
|
||||
} else if ev.HasDefault {
|
||||
fmt.Fprintf(w, " %s%s : %s (default: %s)\n", ev.Name, padding, ev.Description, ev.Default)
|
||||
} else {
|
||||
fmt.Fprintf(w, " %s%s : %s\n", ev.Name, padding, ev.Description)
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user