/
feedback.go
98 lines (68 loc) · 1.76 KB
/
feedback.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
91
92
93
94
95
96
97
98
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/hofstadter-io/hof/cmd/hof/flags"
"github.com/hofstadter-io/hof/cmd/hof/ga"
"github.com/hofstadter-io/hof/lib"
)
var feedbackLong = `Opens an issue or discussion on GitHub with some fields prefilled out`
func init() {
FeedbackCmd.PersistentFlags().BoolVarP(&(flags.FeedbackPflags.Issue), "issue", "i", false, "create an issue (discussion is default)")
FeedbackCmd.PersistentFlags().StringVarP(&(flags.FeedbackPflags.Labels), "labels", "l", "feedback", "labels,comma,separated")
}
func FeedbackRun(args []string) (err error) {
// you can safely comment this print out
// fmt.Println("not implemented")
err = lib.SendFeedback(args, flags.RootPflags, flags.FeedbackPflags)
return err
}
var FeedbackCmd = &cobra.Command{
Use: "feedback <message>",
Aliases: []string{
"hi",
"ask",
"report",
},
Short: "open an issue or discussion on GitHub",
Long: feedbackLong,
Run: func(cmd *cobra.Command, args []string) {
ga.SendCommandPath(cmd.CommandPath())
var err error
// Argument Parsing
err = FeedbackRun(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
func init() {
extra := func(cmd *cobra.Command) bool {
return false
}
ohelp := FeedbackCmd.HelpFunc()
ousage := FeedbackCmd.UsageFunc()
help := func(cmd *cobra.Command, args []string) {
ga.SendCommandPath(cmd.CommandPath() + " help")
if extra(cmd) {
return
}
ohelp(cmd, args)
}
usage := func(cmd *cobra.Command) error {
if extra(cmd) {
return nil
}
return ousage(cmd)
}
thelp := func(cmd *cobra.Command, args []string) {
help(cmd, args)
}
tusage := func(cmd *cobra.Command) error {
return usage(cmd)
}
FeedbackCmd.SetHelpFunc(thelp)
FeedbackCmd.SetUsageFunc(tusage)
}