-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (50 loc) · 1.32 KB
/
main.go
File metadata and controls
59 lines (50 loc) · 1.32 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
package main
import (
"context"
"flag"
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/ekinertac/dtop/docker"
"github.com/ekinertac/dtop/model"
"github.com/ekinertac/dtop/ui"
)
func main() {
// Parse command-line flags
list := flag.Bool("list", false, "List containers and exit (non-interactive)")
listShort := flag.Bool("l", false, "List containers and exit (shorthand)")
version := flag.Bool("version", false, "Print version and exit")
flag.Parse()
// Version flag
if *version {
fmt.Println("dtop v0.3.0")
fmt.Println("Docker container monitor - https://github.com/ekinertac/dtop")
return
}
ctx := context.Background()
// Initialize Docker client
dockerClient, err := docker.NewClient(ctx)
if err != nil {
fmt.Printf("Failed to create Docker client: %v\n", err)
os.Exit(1)
}
defer dockerClient.Close()
// List mode - print once and exit
if *list || *listShort {
containers, err := dockerClient.ListContainers()
if err != nil {
fmt.Printf("Failed to list containers: %v\n", err)
os.Exit(1)
}
tree := model.BuildTree(containers)
ui.PrintSnapshot(tree)
return
}
// Interactive mode - start TUI
m := ui.NewModel(dockerClient)
p := tea.NewProgram(m, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Printf("Error running program: %v\n", err)
os.Exit(1)
}
}