-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (69 loc) · 1.82 KB
/
Copy pathmain.go
File metadata and controls
79 lines (69 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"flag"
"fmt"
"log/slog"
"os"
tea "charm.land/bubbletea/v2"
"github.com/tokuhirom/dcv/internal/config"
"github.com/tokuhirom/dcv/internal/ui"
)
func main() {
// Parse command-line flags
var debugLog string
flag.StringVar(&debugLog, "debug", "", "enable debug logging to a file")
flag.Parse()
setupLog(debugLog)
// Load configuration
cfg, err := config.Load()
if err != nil {
fmt.Printf("Error loading configuration: %v\n", err)
os.Exit(1)
}
// Determine initial view from config
var initialView ui.ViewType
switch cfg.General.InitialView {
case "compose":
initialView = ui.ComposeProcessListView
case "projects":
initialView = ui.ComposeProjectListView
case "docker":
initialView = ui.DockerContainerListView
case "":
// Empty is valid, use default
initialView = ui.DockerContainerListView
default:
slog.Warn("Unknown initial_view in config, using default",
slog.String("initial_view", cfg.General.InitialView),
slog.String("valid_values", "docker, compose, projects"))
initialView = ui.DockerContainerListView
}
slog.Info("Starting dcv",
slog.String("initial_view", cfg.General.InitialView))
m := ui.NewModel(initialView)
p := tea.NewProgram(m)
if _, err := p.Run(); err != nil {
fmt.Printf("Error running program: %v\n", err)
os.Exit(1)
}
}
func setupLog(debugLog string) {
if debugLog != "" {
logFile, err := os.OpenFile(debugLog,
os.O_CREATE|os.O_WRONLY|os.O_APPEND,
0600)
if err != nil {
slog.Error("failed to open log file",
slog.Any("error", err))
os.Exit(1)
}
handler := slog.NewTextHandler(logFile, &slog.HandlerOptions{
Level: slog.LevelDebug,
})
logger := slog.New(handler)
slog.SetDefault(logger)
} else {
// Set the default logger to discard if no debug log is specified
slog.SetDefault(slog.New(slog.DiscardHandler))
}
}