-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
68 lines (59 loc) · 1.58 KB
/
root.go
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 (c) 2023 0x6flab
//
// SPDX-License-Identifier: GPL-3.0-only
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <https://www.gnu.org/licenses/>.
package cmd
import (
"os"
"time"
"github.com/0x6flab/dtop/tui"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/log"
"github.com/spf13/cobra"
)
const (
appName = "dtop"
shortAppDesc = "A graphical CLI for your Docker instance."
longAppDesc = "dtop is a CLI to view and manage your Docker instance."
)
var (
rootCmd = &cobra.Command{
Use: appName,
Short: shortAppDesc,
Long: longAppDesc,
RunE: run,
}
logger = log.NewWithOptions(
os.Stderr,
log.Options{
ReportTimestamp: true,
TimeFormat: time.Kitchen,
Prefix: "dtop 🖥",
},
)
)
func Execute() {
if err := rootCmd.Execute(); err != nil {
logger.Fatal(err)
}
}
func run(cmd *cobra.Command, _ []string) error {
m, err := tui.NewModel(cmd.Context())
if err != nil {
return err
}
if _, err := tea.NewProgram(m, tea.WithAltScreen(), tea.WithContext(cmd.Context())).Run(); err != nil {
logger.Fatal(err)
}
return nil
}