forked from charmbracelet/charm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
90 lines (79 loc) · 1.81 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"fmt"
"log"
"os"
"runtime/debug"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/charm/client"
"github.com/charmbracelet/charm/cmd"
"github.com/charmbracelet/charm/ui"
"github.com/charmbracelet/charm/ui/common"
"github.com/spf13/cobra"
)
var (
Version = ""
CommitSHA = ""
styles = common.DefaultStyles()
rootCmd = &cobra.Command{
Use: "charm",
Short: "Do Charm stuff",
Long: styles.Paragraph.Render(fmt.Sprintf("Do %s stuff. Run without arguments for a TUI or use the sub-commands like a pro.", styles.Keyword.Render("Charm"))),
DisableFlagsInUseLine: true,
RunE: func(cmd *cobra.Command, args []string) error {
if common.IsTTY() {
cfg, err := client.ConfigFromEnv()
if err != nil {
log.Fatal(err)
}
// Log to file, if set
if cfg.Logfile != "" {
f, err := tea.LogToFile(cfg.Logfile, "charm")
if err != nil {
return err
}
defer f.Close() //nolint:errcheck
}
return ui.NewProgram(cfg).Start()
}
return cmd.Help()
},
}
)
func init() {
if len(CommitSHA) >= 7 {
vt := rootCmd.VersionTemplate()
rootCmd.SetVersionTemplate(vt[:len(vt)-1] + " (" + CommitSHA[0:7] + ")\n")
}
if Version == "" {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
Version = info.Main.Version
} else {
Version = "unknown (built from source)"
}
}
rootCmd.Version = Version
rootCmd.AddCommand(
cmd.BioCmd,
cmd.IDCmd,
cmd.JWTCmd,
cmd.KeysCmd,
cmd.LinkCmd("charm"),
cmd.NameCmd,
cmd.BackupKeysCmd,
cmd.ImportKeysCmd,
cmd.KeySyncCmd,
cmd.CompletionCmd,
cmd.ServeCmd,
cmd.PostNewsCmd,
cmd.KVCmd,
cmd.FSCmd,
cmd.CryptCmd,
cmd.MigrateAccountCmd,
)
}
func main() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}