Something went wrong. Try again.
An unofficial terminal client for Tangled, optimized for humans and agents. forked from aly.codes/tg
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127package cli
import ( "fmt"
"github.com/alyraffauf/tg/internal/app" "github.com/spf13/cobra")
func newPRUpdateCommand(service *app.Service) *cobra.Command { var base string
command := &cobra.Command{ Use: "update <record-key>", Short: "Submit a new round for a pull request", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { repoDir, err := getwd() if err != nil { return err } if err := service.UpdatePullRound(cmd.Context(), app.UpdatePullRoundInput{ RepoDir: repoDir, Rkey: args[0], Base: base, }); err != nil { return err } return outputRecordUpdate(cmd, args[0]) }, } command.Flags().StringVarP(&base, "base", "B", "", "Target branch or local remote-tracking branch. Required for forks.") return command}
func newPRCloseCommand(service *app.Service) *cobra.Command { return newPRStateCommand(service, "close", "closed")}
func newPRReopenCommand(service *app.Service) *cobra.Command { return newPRStateCommand(service, "reopen", "open")}
func newPREditCommand(service *app.Service) *cobra.Command { var titleText, bodyText string
command := &cobra.Command{ Use: "edit <record-key>", Short: "Edit a pull request", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { var title, body *string if cmd.Flags().Changed("title") { title = &titleText } if cmd.Flags().Changed("body") { body = &bodyText } if title == nil && body == nil { return fmt.Errorf("provide --title or --body") } if err := service.EditPull(cmd.Context(), args[0], title, body); err != nil { return err } return outputRecordUpdate(cmd, args[0]) }, } command.Flags().StringVarP(&titleText, "title", "t", "", "New title") command.Flags().StringVarP(&bodyText, "body", "b", "", "New body") return command}
func newPRMergeCommand(service *app.Service) *cobra.Command { var repository string
command := &cobra.Command{ Use: "merge <record-key>", Short: "Merge a pull request", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() target, err := resolveTargetFlag(ctx, repository, service) if err != nil { return err } result, err := service.MergePull(ctx, target, args[0]) if err != nil { return err } return output(cmd, result, func(result *app.MergePullResult) { fmt.Fprintf(cmd.OutOrStdout(), "Pull request %s merged\n", result.Rkey) for _, warning := range result.Warnings { fmt.Fprintf(cmd.ErrOrStderr(), "warning: %s\n", warning) } }) }, } command.Flags().StringVarP(&repository, "repo", "R", "", "Target repository as handle/repo") return command}
func newPRStateCommand(service *app.Service, use, status string) *cobra.Command { var repository string
command := &cobra.Command{ Use: use + " <record-key>", Short: use + " a pull request", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() target, err := resolveTargetFlag(ctx, repository, service) if err != nil { return err } result, err := service.SetPullState(ctx, target, args[0], status) if err != nil { return fmt.Errorf("%s pull request: %w", use, err) } return output(cmd, result, func(result *app.StateResult) { fmt.Fprintf(cmd.OutOrStdout(), "Pull request %s %s\n", result.Rkey, result.State) }) }, } command.Flags().StringVarP(&repository, "repo", "R", "", "Target repository as handle/repo") return command}