Something went wrong. Try again.
A command-line interface for tangled, the decentralized Git collaboration platform built on the AT Protocol. eric-wien.tngl.io/tng-cli
cli git atproto tangled
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263package 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 <rkey>", 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}