Something went wrong. Try again.
An unofficial terminal client for Tangled, optimized for humans and agents. tgcli.wisp.place
cli atproto go tangled
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778package cli
import ( "context" "errors" "fmt"
"github.com/alyraffauf/tg/internal/app" "github.com/spf13/cobra")
type issueCreateService interface { CreateIssue(context.Context, app.Target, string, string) (*app.CreatedRecordResult, error) TargetFromCWD(context.Context) (app.Target, error)}
func newIssueCreateCommand(service issueCreateService) *cobra.Command { var bodyText, bodyFile, repository string
command := &cobra.Command{ Use: "create [title]", Short: "Create an issue", Long: `Create an issue.
Without a title or body flag, tg opens $EDITOR. Write the title on the firstline, leave the second line blank, and write the body below it.`, Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() if len(args) == 0 { if cmd.Flags().Changed("body") || cmd.Flags().Changed("body-file") { return fmt.Errorf("title is required when --body or --body-file is used") } target, err := resolveTargetFlag(ctx, repository, service) if err != nil { return err } draft, err := editIssueDraft(ctx, cmd.InOrStdin(), cmd.OutOrStdout(), cmd.ErrOrStderr()) if errors.Is(err, errTitledDraftCanceled) { fmt.Fprintln(cmd.ErrOrStderr(), "Issue creation canceled.") return nil } if err != nil { return err } result, err := service.CreateIssue(ctx, target, draft.Title, draft.Body) if err != nil { return fmt.Errorf("%w; draft saved to %s", err, draft.Path) } removeTitledDraft(draft.Path, "issue", cmd.ErrOrStderr()) return output(cmd, result, func(result *app.CreatedRecordResult) { fmt.Fprintf(cmd.OutOrStdout(), "Created issue %s\n", result.URI) }) }
body, err := commandBody(bodyText, bodyFile) if err != nil { return err } target, err := resolveTargetFlag(ctx, repository, service) if err != nil { return err } result, err := service.CreateIssue(ctx, target, args[0], body) if err != nil { return err } return output(cmd, result, func(result *app.CreatedRecordResult) { fmt.Fprintf(cmd.OutOrStdout(), "Created issue %s\n", result.URI) }) }, } command.Flags().StringVarP(&bodyText, "body", "b", "", "Issue body") command.Flags().StringVarP(&bodyFile, "body-file", "F", "", "Read issue body from file") command.Flags().StringVarP(&repository, "repo", "R", "", "Target repository as handle/repo") return command}