refactor: reduce complexity of main in src/main.rs#382
Merged
jamesadevine merged 1 commit intoMay 1, 2026
Conversation
Extract the Execute command arm (~120 lines of nested logic) into dedicated helper functions: - run_compile: handles Compile arm flags/dispatch - run_execute: orchestrates the Execute pipeline (parse → context → run → memory → summary) - build_execution_context: reads front matter into ExecutionContext, including OTel stats - process_cache_memory: checks cache-memory tool config and processes memory artifacts - print_execution_summary: formats and prints the final results table Also flatten the top-level if-let/match in main to let-else + match, reducing nesting depth. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jamesadevine
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was complex
main()insrc/main.rswas 224 lines with a heuristic complexity score of 44 — the highest in the codebase. The root cause was theExecutecommand arm, which packed ~120 lines of deeply-nested logic directly inside amatcharm:for+if letloop)ExecutionContextfield-by-field with multipleif letbranchesif otel_path.exists()/match/if letif let Some(cm)/if cm.is_enabled()neststd::process::exitwith two separate exit-code branchesThe top-level
if let Some(command) = args.command { match command { ... } } else { ... }also added unnecessary nesting depth.What changed
Four focused helper functions extracted:
run_compile--skip-integrity/--debug-pipelinewarnings and dispatch tocompile_pipeline/compile_all_pipelinesrun_executebuild_execution_contextExecutionContextfromFrontMatter+ CLI overrides + OTel statsprocess_cache_memoryprint_execution_summaryThe top-level
if let ... elsewas replaced withlet Some(command) = args.command else { ... }+ an unconditionalmatch, removing one level of nesting.Before / After
mainlinesVerification
cargo build— clean (0 errors, 0 new warnings)cargo test— all tests passcargo clippy --all-targets --all-features— no new warnings