Skip to content

Commit 547ff8e

Browse files
committed
#6 Complete Create Issue Command With Document function
1 parent c39be3f commit 547ff8e

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

cmd/actions/issue.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@ import (
88
"github.com/spf13/cobra"
99
)
1010

11-
func runGhIssueCreate(title string, body string) (int, error) {
11+
func runGhIssueCreate(title string, body string, doc string) (int, error) {
1212
template := "gh issue create --label enhancement -t \"{{.Title}}\" -b \"{{.Body}}\""
13+
if doc == "" {
14+
if body == "" {
15+
body = title
16+
}
17+
} else {
18+
body, _ = utils.ReadStringFromFile(doc)
19+
}
20+
1321
commandStr := utils.RenderTemplate(template, map[string]string{
1422
"Title": title,
1523
"Body": body,
@@ -20,19 +28,21 @@ func runGhIssueCreate(title string, body string) (int, error) {
2028
func init() {
2129
IssueCmd.Flags().StringVarP(&issueTitle, "title", "t", "", "Title of the issue")
2230
IssueCmd.Flags().StringVarP(&issueBody, "body", "b", "", "Body of the issue")
31+
IssueCmd.Flags().StringVarP(&issueDoc, "doc", "d", "", "Body do of the issue")
2332
IssueCmd.MarkFlagRequired("title")
24-
IssueCmd.MarkFlagRequired("body")
33+
//IssueCmd.MarkFlagRequired("body")
2534
}
2635

2736
var (
2837
issueTitle string
2938
issueBody string
39+
issueDoc string
3040
IssueCmd = &cobra.Command{
3141
Use: "issue",
3242
Short: "Create a new issue",
3343
Long: "Create a new issue with a title and body",
3444
Run: func(cmd *cobra.Command, args []string) {
35-
_, err := runGhIssueCreate(issueTitle, issueBody)
45+
_, err := runGhIssueCreate(issueTitle, issueBody, issueDoc)
3646
if err != nil {
3747
cmd.PrintErrf("Error creating issue: %v\n", err)
3848
}

cmd/actions/starter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212

1313
var CurrentDir = os.Getenv("FLUENT_HOME")
1414

15-
var actions = shell.LoadCommands(path.Join(CurrentDir, "starters.json"))
15+
var starterActions = shell.LoadCommands(path.Join(CurrentDir, "starters.json"))
1616

1717
var (
18-
AvailableStarter = actions.GetAvailableActionNames()
18+
AvailableStarter = starterActions.GetAvailableActionNames()
1919
StarterCmd = &cobra.Command{
2020
Use: "starter",
2121
Short: "fluent start " + strings.Join(AvailableStarter, ","),
@@ -26,7 +26,7 @@ var (
2626
//RunE
2727
Run: func(cmd *cobra.Command, args []string) {
2828
category := args[0]
29-
actions.ExecuteActionByName(category)
29+
starterActions.ExecuteActionByName(category)
3030
},
3131
}
3232
)

internal/utils/fs.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ func DirectoryExist(path string) (bool, error) {
1919
return false, err
2020
}
2121

22-
func WriteStringToFile(content, targetPath string) {
22+
func WriteStringToFile(content, targetPath string) error {
23+
err := os.WriteFile(targetPath, []byte(content), 0644)
24+
if err != nil {
25+
return err
26+
}
27+
return nil
28+
}
2329

30+
func ReadStringFromFile(targetPath string) (string, error) {
31+
file, err := os.ReadFile(targetPath)
32+
if err != nil {
33+
return "", err
34+
}
35+
return string(file), nil
2436
}

0 commit comments

Comments
 (0)