package diff import ( "fmt" "github.com/spf13/cobra" "tangled.org/eric.wien/tng-cli.git/v2/api" gitpkg "tangled.org/eric.wien/tng-cli.git/v2/git" "tangled.org/eric.wien/tng-cli.git/v2/pkg/cmdutil" "tangled.org/eric.wien/tng-cli.git/v2/pkg/iostreams" ) type Options struct { IO *iostreams.IOStreams ApiClient func() (*api.Client, error) BaseRepo func() (*gitpkg.TangledRepo, error) Rkey string } func NewCmdDiff(f *cmdutil.Factory) *cobra.Command { opts := &Options{ IO: f.IOStreams, ApiClient: f.ApiClient, BaseRepo: f.BaseRepo, } cmd := &cobra.Command{ Use: "diff ", Short: "View pull request diff", Long: `Display the patch content of a pull request. Reads the latest patch commits and their diff from the repository\'s knot.`, 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) }, } return cmd } func diffRun(cmd *cobra.Command, opts *Options) error { client, err := opts.ApiClient() if err != nil { return err } resolved, err := cmdutil.ResolveRepo(cmd.Context(), client, opts.BaseRepo) if err != nil { return err } patch, err := client.GetPullPatch(cmd.Context(), resolved.RepoDID, opts.Rkey) if err != nil { return fmt.Errorf("failed to fetch diff: %w", err) } fmt.Fprint(opts.IO.Out, patch) return nil }