Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (56 loc) · 1.94 KB
/
Copy pathmain.go
File metadata and controls
68 lines (56 loc) · 1.94 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
// Copyright Henry Wang
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"flag"
"fmt"
"os"
tea "charm.land/bubbletea/v2"
"github.com/henry118/nerdview/ctr"
"github.com/henry118/nerdview/logging"
)
func main() {
namespace := flag.String("namespace", "default", "containerd namespace")
flag.StringVar(namespace, "n", "default", "containerd namespace (shorthand)")
debug := flag.Bool("debug", false, "enable debug logging to /var/log/nerdview-<pid>.log")
flag.Parse()
if err := logging.Init(*debug); err != nil {
fmt.Fprintf(os.Stderr, "warning: logging disabled: %v\n", err)
}
address := "/run/containerd/containerd.sock"
if env := os.Getenv("CONTAINERD_ADDRESS"); env != "" {
address = env
}
logging.Info("connecting to containerd at %s, namespace=%s", address, *namespace)
client, err := ctr.New(address)
if err != nil {
logging.Error("failed to connect to containerd: %v", err)
fmt.Fprintf(os.Stderr, "failed to connect to containerd: %v\n", err)
os.Exit(1)
}
defer func() { _ = client.Close() }()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client.StartEventStream(ctx)
logging.Info("event stream started")
m := newModel(ctx, client, *namespace)
p := tea.NewProgram(m)
if _, err := p.Run(); err != nil {
logging.Error("program exited with error: %v", err)
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
logging.Info("nerdview exited normally")
}