-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdiscover.go
More file actions
108 lines (97 loc) · 2.99 KB
/
discover.go
File metadata and controls
108 lines (97 loc) · 2.99 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package cmd
import (
"fmt"
"github.com/betterdiscord/cli/internal/betterdiscord"
"github.com/betterdiscord/cli/internal/discord"
"github.com/betterdiscord/cli/internal/models"
"github.com/betterdiscord/cli/internal/output"
"github.com/spf13/cobra"
)
func init() {
discoverCmd.AddCommand(discoverInstallsCmd)
discoverCmd.AddCommand(discoverPathsCmd)
discoverCmd.AddCommand(discoverAddonsCmd)
rootCmd.AddCommand(discoverCmd)
}
var discoverCmd = &cobra.Command{
Use: "discover",
Short: "Discover Discord installations and related data",
RunE: func(cmd *cobra.Command, args []string) error {
return discoverInstallsCmd.RunE(cmd, args)
},
}
var discoverInstallsCmd = &cobra.Command{
Use: "installs",
Short: "Show detected Discord installations",
Long: "Lists detected Discord installations by channel, showing path, version, install type, and BetterDiscord status.",
RunE: func(cmd *cobra.Command, args []string) error {
installs := discord.GetAllInstalls()
if len(installs) == 0 {
output.Println("📭 No Discord installations detected.")
return nil
}
channels := []models.DiscordChannel{models.Stable, models.PTB, models.Canary}
output.Printf("🔎 Discord installations:\n\n")
tw := output.NewTableWriter()
fmt.Fprintln(tw, "CHANNEL\tVERSION\tTYPE\tBD INJECTED\tPATH")
for _, ch := range channels {
arr := installs[ch]
for _, inst := range arr {
typeLabel := "native"
if inst.IsFlatpak {
typeLabel = "flatpak"
} else if inst.IsSnap {
typeLabel = "snap"
}
bdStatus := "no"
if inst.IsInjected() {
bdStatus = "yes"
}
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n", ch.Name(), inst.Version, typeLabel, bdStatus, inst.CorePath)
}
}
return tw.Flush()
},
}
var discoverPathsCmd = &cobra.Command{
Use: "paths",
Short: "Show suggested install paths per channel",
RunE: func(cmd *cobra.Command, args []string) error {
channels := []models.DiscordChannel{models.Stable, models.PTB, models.Canary}
output.Printf("🧭 Suggested install paths:\n\n")
tw := output.NewTableWriter()
fmt.Fprintln(tw, "CHANNEL\tSUGGESTED PATH")
for _, ch := range channels {
p := discord.GetSuggestedPath(ch)
if p == "" {
p = "(none detected)"
}
fmt.Fprintf(tw, "%s\t%s\n", ch.Name(), p)
}
return tw.Flush()
},
}
var discoverAddonsCmd = &cobra.Command{
Use: "addons",
Short: "Summarize installed plugins and themes",
RunE: func(cmd *cobra.Command, args []string) error {
plugins, err := betterdiscord.ListAddons(betterdiscord.AddonPlugin)
if err != nil {
return err
}
themes, err := betterdiscord.ListAddons(betterdiscord.AddonTheme)
if err != nil {
return err
}
output.Printf("🧩 Addons summary:\n")
output.Printf(" Plugins: %d installed\n", len(plugins))
for _, p := range plugins {
output.Printf(" - %s (%s)\n", p.FullFilename, p.Path)
}
output.Printf(" Themes: %d installed\n", len(themes))
for _, t := range themes {
output.Printf(" - %s (%s)\n", t.FullFilename, t.Path)
}
return nil
},
}