package diff import ( "fmt" "github.com/spf13/cobra" "tangled.org/eric.wien/tng-cli/api" "tangled.org/eric.wien/tng-cli/pkg/cmdutil" "tangled.org/eric.wien/tng-cli/pkg/iostreams" ) type Options struct { IO *iostreams.IOStreams ApiClient func() (*api.Client, error) Rkey string Author string } func NewCmdDiff(f *cmdutil.Factory) *cobra.Command { opts := &Options{ IO: f.IOStreams, ApiClient: f.ApiClient, } cmd := &cobra.Command{ Use: "diff ", Short: "View pull request diff", Long: `Display the patch content of a pull request. Downloads and decompresses the patch blob from the PR's AT Protocol record.`, Example: ` tng pr diff 3jxn7q7bklr2r`, Args: cmdutil.ExactArgs(1, "pull request rkey is required"), RunE: func(cmd *cobra.Command, args []string) error { opts.Rkey = args[0] return diffRun(cmd, opts) }, } cmd.Flags().StringVar(&opts.Author, "author", "", "DID of the PR author (defaults to you)") return cmd } func diffRun(cmd *cobra.Command, opts *Options) error { client, err := opts.ApiClient() if err != nil { return err } authorDID := opts.Author if authorDID == "" { authorDID = client.DID().String() } patch, err := client.GetPullPatch(cmd.Context(), authorDID, opts.Rkey) if err != nil { return fmt.Errorf("failed to fetch diff: %w", err) } fmt.Fprint(opts.IO.Out, patch) return nil }