Skip to content

Split CLI lib.rs into modules#2290

Open
john-h-kastner-aws wants to merge 1 commit intomainfrom
cli-lib-split
Open

Split CLI lib.rs into modules#2290
john-h-kastner-aws wants to merge 1 commit intomainfrom
cli-lib-split

Conversation

@john-h-kastner-aws
Copy link
Copy Markdown
Contributor

@john-h-kastner-aws john-h-kastner-aws commented Apr 3, 2026

Description of changes

Sorry for the large diff, but this has been bothering me for a while. I hope you can trust that I haven't changed any of the code.

I want to do something similar for api.rs in cedar-policy, but that's a larger project.

Issue #, if available

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A breaking change requiring a major version bump to cedar-policy (e.g., changes to the signature of an existing API).
  • A backwards-compatible change requiring a minor version bump to cedar-policy (e.g., addition of a new API).
  • A bug fix or other functionality change requiring a patch to cedar-policy.
  • A change "invisible" to users (e.g., documentation, changes to "internal" crates like cedar-policy-core, cedar-validator, etc.)
  • A change (breaking or otherwise) that only impacts unreleased or experimental code.

I confirm that this PR (choose one, and delete the other options):

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).
  • Does not update the CHANGELOG because my change does not significantly impact released code.

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-spec, and how you have tested that your updates are correct.)
  • Requires updates, but I do not plan to make them in the near future. (Make sure that your changes are hidden behind a feature flag to mark them as experimental.)
  • I'm not sure how my change impacts cedar-spec. (Post your PR anyways, and we'll discuss in the comments.)

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar language specification.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-docs. PRs should be targeted at a staging-X.Y branch, not main.)
  • I'm not sure how my change impacts the documentation. (Post your PR anyways, and we'll discuss in the comments.)

Signed-off-by: John Kastner <jkastner@amazon.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Cedar CLI's lib.rs by splitting it into well-organized modules. The large monolithic library file is being restructured into a hierarchical module system with:

  • A command/ module containing individual files for each CLI subcommand
  • A utils/ module containing shared utility functions for reading schemas, policies, requests, and entities

Changes:

  • Split lib.rs into modular structure with command.rs and utils.rs as the main module hubs
  • Created 19 new command-specific files in cedar-policy-cli/src/command/ directory for each subcommand
  • Created 5 new utility files in cedar-policy-cli/src/utils/ directory for shared functionality
  • Maintained all existing functionality without code logic changes; this is purely organizational

Reviewed changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cedar-policy-cli/src/lib.rs Reduced to 108 lines, now imports from command and utils modules
cedar-policy-cli/src/command.rs New file defining Commands enum and re-exporting from 15 command submodules
cedar-policy-cli/src/command/*.rs New files containing implementation for each CLI command (authorize, evaluate, validate, etc.)
cedar-policy-cli/src/utils.rs New file organizing utility modules and re-exporting helper functions
cedar-policy-cli/src/utils/*.rs New files containing schema, policies, request, entities, and links utilities

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Coverage Report

Head Commit: f3d5e17ca055659bae4b1c364e940f4e2ad11ab0

Base Commit: 4cb5358632b2e1bb8e5c8b9a6fc2bfb5a8119bcf

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 72.47%

Status: FAILED ❌

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/command/authorize.rs 🟢 69/80 86.25% 72-75, 118-120, 137-140
cedar-policy-cli/src/command/check_parse.rs 🔴 28/45 62.22% 49-58, 82-85, 92-94
cedar-policy-cli/src/command/evaluate.rs 🟢 29/33 87.88% 48-50, 69
cedar-policy-cli/src/command/format.rs 🟢 27/31 87.10% 52-54, 85
cedar-policy-cli/src/command/language_version.rs 🔴 0/5 0.00% 21-23, 27-28
cedar-policy-cli/src/command/link.rs 🟡 41/53 77.36% 55, 57-60, 62, 68-70, 89, 104-105
cedar-policy-cli/src/command/new.rs 🔴 0/82 0.00% 31-34, 36, 38, 40-49, 52-86, 88-89, 91-93, 101-102, 104-125, 127-128
cedar-policy-cli/src/command/partial_eval.rs 🔴 0/149 0.00% 90-99, 102-120, 124-133, 135-141, 143-145, 147-156, 158-163, 165-170, 172-176, 178, 180, 198-201, 204-211, 213-214, 216-217, 220-221, 224-229, 232-236, 239, 242-254, 257-261, 264-268, 271-283, 285-288, 291
cedar-policy-cli/src/command/run_test.rs 🟢 139/154 90.26% 82, 84-88, 123, 256, 260, 263, 267, 270, 274, 277, 281
cedar-policy-cli/src/command/symcc.rs 🟢 340/371 91.64% 111, 191-194, 203-205, 234-235, 340, 476-480, 500-504, 584-588, 604-608
cedar-policy-cli/src/command/tpe.rs 🔴 91/134 67.91% 144-145, 149-150, 171, 176-179, 185-189, 193-195, 200-202, 208-210, 222-225, 229-230, 246-248, 252-255, 274, 276, 278, 280-281, 283, 285
cedar-policy-cli/src/command/translate_policy.rs 🟢 25/30 83.33% 50-52, 71-72
cedar-policy-cli/src/command/translate_schema.rs 🟢 39/42 92.86% 81-83
cedar-policy-cli/src/command/validate.rs 🟢 26/32 81.25% 60-61, 64, 69-70, 73
cedar-policy-cli/src/command/visualize.rs 🔴 6/9 66.67% 33-35
cedar-policy-cli/src/utils.rs 🟢 20/20 100.00%
cedar-policy-cli/src/utils/entities.rs 🟢 13/16 81.25% 32, 34, 36
cedar-policy-cli/src/utils/links.rs 🟢 53/60 88.33% 33, 98, 120-124
cedar-policy-cli/src/utils/policies.rs 🟢 87/98 88.78% 104-106, 108-109, 125-127, 129-130, 144
cedar-policy-cli/src/utils/request.rs 🟢 67/78 85.90% 67-68, 70-71, 73-74, 85, 138, 142-144
cedar-policy-cli/src/utils/schema.rs 🟢 19/22 86.36% 83-85

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.55%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4722/5102 92.55% --
cedar-policy 🟡 4226/5353 78.95% --
cedar-policy-cli 🟡 1147/1592 72.05% --
cedar-policy-core 🟢 24002/27279 87.99% --
cedar-policy-formatter 🟢 914/1088 84.01% --
cedar-policy-symcc 🟢 6752/7262 92.98% --
cedar-wasm 🔴 0/28 0.00% --

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Coverage Report

Head Commit: fa4992104c74b450298ebec8edd3e8c8daf614d7

Base Commit: 4cb5358632b2e1bb8e5c8b9a6fc2bfb5a8119bcf

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 72.47%

Status: FAILED ❌

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/command/authorize.rs 🟢 69/80 86.25% 72-75, 118-120, 137-140
cedar-policy-cli/src/command/check_parse.rs 🔴 28/45 62.22% 49-58, 82-85, 92-94
cedar-policy-cli/src/command/evaluate.rs 🟢 29/33 87.88% 48-50, 69
cedar-policy-cli/src/command/format.rs 🟢 27/31 87.10% 52-54, 85
cedar-policy-cli/src/command/language_version.rs 🔴 0/5 0.00% 21-23, 27-28
cedar-policy-cli/src/command/link.rs 🟡 41/53 77.36% 55, 57-60, 62, 68-70, 89, 104-105
cedar-policy-cli/src/command/new.rs 🔴 0/82 0.00% 31-34, 36, 38, 40-49, 52-86, 88-89, 91-93, 101-102, 104-125, 127-128
cedar-policy-cli/src/command/partial_eval.rs 🔴 0/149 0.00% 90-99, 102-120, 124-133, 135-141, 143-145, 147-156, 158-163, 165-170, 172-176, 178, 180, 198-201, 204-211, 213-214, 216-217, 220-221, 224-229, 232-236, 239, 242-254, 257-261, 264-268, 271-283, 285-288, 291
cedar-policy-cli/src/command/run_test.rs 🟢 139/154 90.26% 82, 84-88, 123, 256, 260, 263, 267, 270, 274, 277, 281
cedar-policy-cli/src/command/symcc.rs 🟢 340/371 91.64% 111, 191-194, 203-205, 234-235, 340, 476-480, 500-504, 584-588, 604-608
cedar-policy-cli/src/command/tpe.rs 🔴 91/134 67.91% 144-145, 149-150, 171, 176-179, 185-189, 193-195, 200-202, 208-210, 222-225, 229-230, 246-248, 252-255, 274, 276, 278, 280-281, 283, 285
cedar-policy-cli/src/command/translate_policy.rs 🟢 25/30 83.33% 50-52, 71-72
cedar-policy-cli/src/command/translate_schema.rs 🟢 39/42 92.86% 81-83
cedar-policy-cli/src/command/validate.rs 🟢 26/32 81.25% 60-61, 64, 69-70, 73
cedar-policy-cli/src/command/visualize.rs 🔴 6/9 66.67% 33-35
cedar-policy-cli/src/utils.rs 🟢 20/20 100.00%
cedar-policy-cli/src/utils/entities.rs 🟢 13/16 81.25% 32, 34, 36
cedar-policy-cli/src/utils/links.rs 🟢 53/60 88.33% 33, 98, 120-124
cedar-policy-cli/src/utils/policies.rs 🟢 87/98 88.78% 104-106, 108-109, 125-127, 129-130, 144
cedar-policy-cli/src/utils/request.rs 🟢 67/78 85.90% 67-68, 70-71, 73-74, 85, 138, 142-144
cedar-policy-cli/src/utils/schema.rs 🟢 19/22 86.36% 83-85

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.55%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4722/5102 92.55% --
cedar-policy 🟡 4226/5353 78.95% --
cedar-policy-cli 🟡 1147/1592 72.05% --
cedar-policy-core 🟢 24002/27279 87.99% --
cedar-policy-formatter 🟢 914/1088 84.01% --
cedar-policy-symcc 🟢 6752/7262 92.98% --
cedar-wasm 🔴 0/28 0.00% --

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.

4 participants