forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discuss.go
68 lines (55 loc) · 1.53 KB
/
discuss.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
package cmd
import (
"bytes"
_ "embed"
"net/url"
"os"
"path/filepath"
"text/template"
"github.com/cli/browser"
"github.com/evcc-io/evcc/server"
"github.com/spf13/cobra"
)
// discussCmd represents the discuss command
var discussCmd = &cobra.Command{
Use: "discuss",
Short: "Request support at Github Discussions (https://github.com/evcc-io/evcc/discussions/categories/erste-hilfe)",
Run: runDiscuss,
}
//go:embed discuss.tpl
var discussTmpl string
func init() {
rootCmd.AddCommand(discussCmd)
}
func errorString(err error) string {
if err != nil {
return err.Error()
}
return ""
}
func runDiscuss(cmd *cobra.Command, args []string) {
cfgErr := loadConfigFile(&conf, !cmd.Flag(flagIgnoreDatabase).Changed)
file, pathErr := filepath.Abs(cfgFile)
if pathErr != nil {
file = cfgFile
}
var redacted string
if src, err := os.ReadFile(cfgFile); err == nil {
redacted = redact(string(src))
}
tmpl := template.Must(template.New("discuss").Parse(discussTmpl))
out := new(bytes.Buffer)
_ = tmpl.Execute(out, map[string]any{
"CfgFile": file,
"CfgError": errorString(cfgErr),
"CfgContent": redacted,
"Version": server.FormattedVersion(),
})
body := out.String()
uri := "https://github.com/evcc-io/evcc/discussions/new?category=erste-hilfe&body=" + url.QueryEscape(body)
if err := browser.OpenURL(uri); err != nil {
log.FATAL.Println("Could not open browser.")
log.FATAL.Println("Go to https://github.com/evcc-io/evcc/discussions/new?category=erste-hilfe and post the following:")
log.FATAL.Println(body)
}
}