package cli import ( "fmt" "strings" "github.com/spf13/cobra" "github.com/m3tam3re/agent-lib/internal/vendor" ) func newVendorCmd() *cobra.Command { cmd := &cobra.Command{ Use: "vendor", Short: "Curate external sources into this work repository", } cmd.AddCommand(newVendorAddCmd()) cmd.AddCommand(newVendorListCmd()) cmd.AddCommand(newVendorInspectCmd()) cmd.AddCommand(newVendorUpdateCmd()) cmd.AddCommand(newVendorDiffCmd()) cmd.AddCommand(newVendorRemoveCmd()) return cmd } func newVendorAddCmd() *cobra.Command { var ref string var include []string var renames []string cmd := &cobra.Command{ Use: "add ", Short: "Vendor a new external git source", Long: "Clones the source (in-process, via go-git), discovers skills, commands,\n" + "agents and MCP fragments, materializes the selection under external//\n" + "and pins URL, ref, revision, selection and renames in the lockfile.\n" + "Default selection is everything; --include switches to an explicit list.\n" + "Collisions abort with a hard error; resolve them with --rename upstream=deployed.", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { renameMap, err := vendor.ParseRenames(renames) if err != nil { return err } opts := vendor.AddOptions{ Name: args[0], URL: args[1], Ref: ref, Include: splitList(include), Renames: renameMap, } if err := vendor.Add(".", opts, cmd.OutOrStdout()); err != nil { return fmt.Errorf("vendor add: %w", err) } return nil }, } cmd.Flags().StringVar(&ref, "ref", "", "branch or tag to track (default: the source's default branch)") cmd.Flags().StringSliceVar(&include, "include", nil, "comma-separated item ids to vendor (switches selection to include mode)") cmd.Flags().StringSliceVar(&renames, "rename", nil, "deployed-name override upstream-id=deployed-name (repeatable)") return cmd } func splitList(in []string) []string { var out []string for _, s := range in { for _, part := range strings.Split(s, ",") { if t := strings.TrimSpace(part); t != "" { out = append(out, t) } } } return out }