Skip to content

feat: add field management commands#76

Merged
angeloashmore merged 13 commits intomainfrom
aa/field-commands
Mar 28, 2026
Merged

feat: add field management commands#76
angeloashmore merged 13 commits intomainfrom
aa/field-commands

Conversation

@angeloashmore
Copy link
Copy Markdown
Member

@angeloashmore angeloashmore commented Mar 27, 2026

Resolves: #21, #22

Description

Adds a prismic field command group for managing fields on local slice, page type, and custom type models. This enables full content modeling from the CLI without needing to use the Prismic editor.

Commands:

  • prismic field add <type> <id> --to <model> — Add a field to a model.
  • prismic field list --from <model> — List all fields on a model.
  • prismic field remove <id> --from <model> — Remove a field from a model.

Supported field types for field add:

  • boolean
  • color
  • date
  • embed
  • geopoint
  • number
  • text
  • timestamp
  • rich-text
  • select
  • table
  • image
  • link
  • link-to-media
  • content-relationship
  • integration
  • group
  • uid (page types and custom types only)

Each field type has its own subcommand with type-specific flags (e.g. --default-value, --placeholder, --allow).

The --to flag accepts a relative path to a model.json (slice) or index.json (page/custom type). For slices, --variation selects the variation (defaults to "default"). For types, --tab selects the tab (defaults to "Main").

Field IDs support dot-notation paths (e.g. my_group.my_field) to target fields nested inside groups.

Checklist

  • A comprehensive Linear ticket, providing sufficient context and details to facilitate the review of the PR, is linked to the PR.
  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

# Add a text field to a slice
prismic field add text title --to slices/Hero/model.json --label "Title"

# Add a rich text field with specific block types
prismic field add rich-text description --to slices/Hero/model.json \
  --allow heading1,paragraph,strong,em --single

# Add a select field with options
prismic field add select color --to customtypes/page/index.json \
  --option red --option green --option blue --default-value red

# Add a link field to a specific custom type tab
prismic field add link cta_link --to customtypes/page/index.json \
  --tab "CTA" --allow-target-blank

# Add a field inside a group using dot-notation
prismic field add text cards.name --to slices/Hero/model.json

# Add a boolean field with labels
prismic field add boolean is_featured --to customtypes/blog_post/index.json \
  --true-label "Featured" --false-label "Not featured"

# Target a specific slice variation
prismic field add image background --to slices/Hero/model.json \
  --variation "withBackground"

# List all fields on a slice
prismic field list --from slices/Hero/model.json

# Remove a field
prismic field remove old_field --from slices/Hero/model.json

How to QA 1


Note

Medium Risk
Adds new CLI surface area that mutates local slice/custom type JSON models (including nested group targeting), so mistakes could overwrite models or generate incorrect types despite having good e2e coverage.

Overview
Introduces a new prismic field command group with add, list, and remove subcommands to manage fields on local slice and custom type models, and wires it into the main CLI router.

field add supports multiple field-type subcommands (e.g. boolean, rich-text, link, uid, etc.), applies type-specific flags, prevents overwriting existing fields, and regenerates types after saving. Model targeting is centralized in new resolveModel/resolveFieldTarget helpers to support --to/--from, slice --variation, type --tab, and dot-notation for nested group fields; extensive new tests cover add/list/remove flows and error cases.

Written by Cursor Bugbot for commit 44cc21e. This will update automatically on new commits. Configure here.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

@angeloashmore angeloashmore force-pushed the aa/field-commands branch 3 times, most recently from 93f91ff to ade75cc Compare March 27, 2026 04:11
angeloashmore and others added 3 commits March 27, 2026 12:18
Adds CLI commands for managing fields on slices, page types, and custom
types. Includes `field add`, `field list`, and `field remove` with
target flags (`--slice`, `--page-type`, `--custom-type`) to specify
where fields are managed.

Also refactors `createCommand` to support declarative `required`
validation on positionals and options, removing manual checks across
all existing commands.

Resolves #21
Resolves #22

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Moves `resolveModel` and `TARGET_OPTIONS` into `src/models.ts` so they
can be reused outside the field command tree.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace --slice/--page-type/--custom-type flags with a single --to flag
that accepts a relative path to the model directory. Inline upsert helpers
into adapter methods, extract shared test builders, and add integration
tests for field add/remove/list commands.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
angeloashmore and others added 5 commits March 27, 2026 13:32
Add dedicated commands for each field type (color, date, embed, geopoint,
integration, number, text, timestamp, uid) with type-specific flags and
validation. Update the field-add router to dispatch to these subcommands
and extend the models module with field type definitions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add dedicated `field add` subcommands for content-relationship, image,
link-to-media, rich-text, select, and table fields with type-specific
options and tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds `resolveFieldTarget` to resolve dot-separated field paths (e.g.,
`group.fieldName`) so fields can be added inside groups. Updates all
field-add commands to use the new resolution and defers label
derivation until after the field ID is resolved.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@angeloashmore angeloashmore marked this pull request as ready for review March 28, 2026 01:07
angeloashmore and others added 2 commits March 27, 2026 15:25
These commands read from a source rather than writing to a target,
so `--from` better communicates intent.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Uses `resolveFieldTarget` to support dot notation (e.g. `my_group.subtitle`)
for removing fields inside groups. Also fixes number parsing to use
`Number()` instead of `Number.parseInt()` for decimal support.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…veModel`

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Matches the editor's behavior where omitting block types enables all of them.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@angeloashmore angeloashmore merged commit afd0e13 into main Mar 28, 2026
13 checks passed
@angeloashmore angeloashmore deleted the aa/field-commands branch March 28, 2026 02:07
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

throw new CommandError(`--${optionName} must be a valid number, got "${value}"`);
}
return number;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseNumber silently accepts empty strings and Infinity

Low Severity

parseNumber uses Number(value) followed by a Number.isNaN() check, but Number("") returns 0 (not NaN) and Number("Infinity") returns Infinity. This means --min "" is silently accepted as 0, and --min Infinity is accepted as Infinity, both bypassing the validation intended to reject non-numeric input.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Design API-first modeling approach

1 participant