Add discuss command (#4659)
This commit is contained in:
parent
ea79afee58
commit
97bf4acab1
4 changed files with 106 additions and 0 deletions
76
cmd/discuss.go
Normal file
76
cmd/discuss.go
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
//go:build !windows
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/evcc-io/evcc/server"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/pkg/browser"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
util.LogLevel(viper.GetString("log"), viper.GetStringMapString("levels"))
|
||||
log.INFO.Printf("evcc %s", server.FormattedVersion())
|
||||
|
||||
cfgErr := loadConfigFile(&conf)
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
tmpl := template.Must(template.New("discuss").Funcs(sprig.FuncMap()).Parse(discussTmpl))
|
||||
|
||||
_ = 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)
|
||||
}
|
||||
}
|
||||
26
cmd/discuss.tpl
Normal file
26
cmd/discuss.tpl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<!-- Detaillierte Problembeschreibung bitte hier -->
|
||||
|
||||
|
||||
|
||||
{{ if .CfgError -}}
|
||||
Fehlermeldung:
|
||||
|
||||
```
|
||||
{{ .CfgError }}
|
||||
```
|
||||
|
||||
{{ end -}}
|
||||
|
||||
{{ if .CfgContent -}}
|
||||
<details><summary>Konfiguration{{ if .CfgFile }} ({{ .CfgFile }}){{ end }}</summary>
|
||||
|
||||
```yaml
|
||||
{{ .CfgContent }}
|
||||
```
|
||||
|
||||
</details>
|
||||
{{ end -}}
|
||||
|
||||
{{ if .Version -}}
|
||||
Version: `{{ .Version }}`
|
||||
{{ end -}}
|
||||
1
go.mod
1
go.mod
|
|
@ -64,6 +64,7 @@ require (
|
|||
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/philippseith/signalr v0.6.1-0.20220829124759-bd5ffb679356
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
|
||||
github.com/prometheus/client_golang v1.13.0
|
||||
github.com/prometheus/common v0.37.0
|
||||
github.com/robertkrimen/otto v0.0.0-20211024170158-b87d35c0b86f
|
||||
|
|
|
|||
3
go.sum
3
go.sum
|
|
@ -711,6 +711,8 @@ github.com/philippseith/signalr v0.6.1-0.20220829124759-bd5ffb679356 h1:YTrZVN3A
|
|||
github.com/philippseith/signalr v0.6.1-0.20220829124759-bd5ffb679356/go.mod h1:8tC01OFK/CNtKSZbwLOavvLYxmEMaQXOsY4Ut69QKM4=
|
||||
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
|
@ -1144,6 +1146,7 @@ golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue