mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-30 16:55:25 +01:00 
			
		
		
		
	tea comment: handle piped stdin (#322)
fixes #321 Co-authored-by: Norwin Roosen <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/322 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
		| @@ -6,6 +6,7 @@ package cmd | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"strings" | ||||
|  | ||||
| 	"code.gitea.io/tea/modules/interact" | ||||
| @@ -45,12 +46,23 @@ func runAddComment(cmd *cli.Context) error { | ||||
| 	} | ||||
|  | ||||
| 	body := strings.Join(ctx.Args().Tail(), " ") | ||||
| 	if len(body) == 0 { | ||||
| 	if interact.IsStdinPiped() { | ||||
| 		// custom solution until https://github.com/AlecAivazis/survey/issues/328 is fixed | ||||
| 		if bodyStdin, err := ioutil.ReadAll(ctx.App.Reader); err != nil { | ||||
| 			return err | ||||
| 		} else if len(bodyStdin) != 0 { | ||||
| 			body = strings.Join([]string{body, string(bodyStdin)}, "\n\n") | ||||
| 		} | ||||
| 	} else if len(body) == 0 { | ||||
| 		if body, err = interact.PromptMultiline("Content"); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if len(body) == 0 { | ||||
| 		return fmt.Errorf("No comment body provided") | ||||
| 	} | ||||
|  | ||||
| 	client := ctx.Login.Client() | ||||
| 	comment, _, err := client.CreateIssueComment(ctx.Owner, ctx.Repo, idx, gitea.CreateIssueCommentOption{ | ||||
| 		Body: body, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Norwin
					Norwin