CLI command design

variants

Inspects and edits project variants in Altium .PrjPcb files.

Purpose

variants is a project-level convenience command for common variant maintenance. Each write action is implemented as a single MCO operation so generated workflows and terminal users share the same mutation behavior.

Usage

altium-cruncher variants
altium-cruncher variants list
altium-cruncher variants list project.PrjPcb --json
altium-cruncher variants delete A --project project.PrjPcb
altium-cruncher variants rename A A1
altium-cruncher variants clone A A-debug --current
altium-cruncher variants toggle-dnp A R15 --unique-id \QTUCRUVF

Arguments

When no project path is supplied, the command requires exactly one .PrjPcb in the current directory. Running variants with no subcommand is shorthand for variants list when that project can be resolved. Multiple local projects are listed and the user must pass one explicitly with the optional positional project path or --project. list accepts --json and --no-color. Mutation subcommands accept --dry-run and --json. clone accepts --unique-id, --allow-fabrication, --no-allow-fabrication, and --current. toggle-dnp accepts an optional Altium variation --unique-id; when omitted while marking DNP, the command attempts to infer it from an exact schematic designator match. Calling toggle-dnp for a designator already marked Not Fitted removes that DNP variation row.

The underlying MCO operations are project.list_variants, project.delete_variant, project.rename_variant, project.clone_variant, and project.toggle_variant_dnp. The lower-level project.add_variant_dnp operation remains available for deterministic generated workflows that only want to set DNP.

Output

Human list output uses Rich tables. The summary table reports DNP and change counts instead of repeating every designator, then change details are grouped as variant panels containing schematic-sheet tables. Change tables omit a Variant column because the panel title owns that context and include a Value column resolved from component Comment first, then Value. Terminal color highlights DNP rows when enabled, while --no-color keeps bordered, width-aware ASCII tables for readable captured output. Altium parameter expressions such as =Value are resolved in pretty output without showing the source expression suffix.

JSON list output uses altium_cruncher.variants.list.a0 and includes the project path, current variant, variant summaries, flattened change rows, schematic-index warnings, raw expression values, resolved component values, and resolved values for alternate parts and parameter overrides. Mutation commands print the MCO operation message by default with blank-line padding, or the full MCO execution result with --json.

Tests

Unit coverage verifies MCO variant mutation round-trips and CLI project auto-detection, JSON output, DNP toggling, missing-argument variant hints, =Value resolution, and ambiguous project errors.