-
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters