feat(vendor): select command — manage include/exclude selection after initial add

vendor select <name> --add/--remove/--mode all changes what a source
contributes without advancing the pinned rev: ids are validated against
the pinned upstream (typos abort listing available ids), collisions
re-run, renames from the lockfile are honored, and the external area is
rewritten via the same staging-swap as update. include mode grows and
shrinks the include list; all mode --remove moves ids onto exclude;
--mode all resets to everything. Failed selects mutate nothing.

Closes beads: agent-lib-cd3
This commit is contained in:
2026-08-23 15:13:50 +02:00
parent 7070d8cc25
commit 876ff1c6b9
5 changed files with 624 additions and 1 deletions
+37
View File
@@ -15,6 +15,7 @@ func newVendorCmd() *cobra.Command {
Short: "Curate external sources into this work repository",
}
cmd.AddCommand(newVendorAddCmd())
cmd.AddCommand(newVendorSelectCmd())
cmd.AddCommand(newVendorListCmd())
cmd.AddCommand(newVendorInspectCmd())
cmd.AddCommand(newVendorUpdateCmd())
@@ -71,3 +72,39 @@ func splitList(in []string) []string {
}
return out
}
func newVendorSelectCmd() *cobra.Command {
var add, remove []string
var mode string
cmd := &cobra.Command{
Use: "select <name>",
Short: "Change a source's selection without advancing the pinned revision",
Long: "Manages include/exclude selection after the initial vendor add.\n" +
"Include mode: --add appends ids (validated against the pinned upstream),\n" +
"--remove drops ids and deletes their folders. All mode: --remove moves ids\n" +
"onto the exclude list; --add is an error (everything is selected already).\n" +
"--mode all resets to everything: include/exclude lists are cleared and the\n" +
"full pinned upstream is re-materialized. Collisions re-run on every change;\n" +
"renames from the lockfile are honored. The revision never moves — that is\n" +
"vendor update's job.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if mode != "" && mode != "all" {
return fmt.Errorf("--mode accepts only \"all\" (got %q)", mode)
}
opts := vendor.SelectOptions{
Add: splitList(add),
Remove: splitList(remove),
ModeAll: mode == "all",
}
if _, err := vendor.Select(".", args[0], opts, cmd.OutOrStdout()); err != nil {
return fmt.Errorf("vendor select: %w", err)
}
return nil
},
}
cmd.Flags().StringSliceVar(&add, "add", nil, "comma-separated upstream ids to add to the selection")
cmd.Flags().StringSliceVar(&remove, "remove", nil, "comma-separated upstream ids to remove from the selection")
cmd.Flags().StringVar(&mode, "mode", "", "switch selection mode (only \"all\": clear include/exclude, take everything)")
return cmd
}