Skip to content

refactor: reduce complexity of main() dispatch in src/main.rs - #1868

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-main-dispatch-5a5ec8b4d1fbc3fb
Draft

refactor: reduce complexity of main() dispatch in src/main.rs#1868
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-main-dispatch-5a5ec8b4d1fbc3fb

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

async fn main() in src/main.rs was flagged by clippy::too_many_lines at 492/100 lines. It contained a single giant match command { ... } dispatching all ~26 CLI subcommands (Compile, Check, Mcp, McpAuthor, Execute, Init, Configure, Secrets, Enable, Disable, Remove, List, Status, Run, Audit, Trace, Inspect, Graph, Whatif, Lint, Catalog, and four Export* variants), making it hard to read, test, or modify safely.

What changed

Extracted the dispatch logic into a small hierarchy of focused, delegating async functions, grouped by related concern:

  • dispatch_command(command: Commands) -> Result<()> — top-level dispatcher; handles Compile/Check/Mcp (via handle_compile_check_mcp_command), McpAuthor (inline), Execute (via handle_execute_command), Init (inline), and delegates lifecycle/inspection command groups.
  • handle_compile_check_mcp_command — Compile, Check, Mcp.
  • handle_execute_command — Execute (including --prepare-custom-agent-output logic).
  • dispatch_lifecycle_command — Enable, Disable, Remove, List, Status, Run inline; delegates Configure/Secrets.
  • handle_configure_secrets_command — Configure, Secrets (Set/List/Delete).
  • dispatch_inspect_command — Audit, Trace, Inspect, Graph (Dump/Deps/Outputs), Whatif, Lint, Catalog; delegates Export*.
  • handle_export_command — the four ExportGateSchema/ExportFactCatalog/ExportAdoProxyCatalogSchema/ExportAdoProxyCatalog variants.

main() itself is now ~40 lines: parse args, init logging, spawn update check, call dispatch_command(command).await?, await update-check handle.

This is a purely mechanical, structural refactor — match-arm bodies were moved verbatim into new functions (each satisfying Rust's match exhaustiveness with _ => unreachable!("...") catch-alls, since callers only ever route valid variant subsets). No public API or observable behavior changes.

Before / after

  • Before: single main() at 492 lines.
  • After: main() ~40 lines; largest remaining sub-function ~133 lines (further splitting would fragment cohesive command groups without meaningful readability gain).

Verification

  • cargo build — clean.
  • cargo test --bin ado-aw — all 2948 tests pass, 1 ignored, 0 failed.
  • cargo clippy --all-targets --all-features (default lints) — clean, no warnings.
  • Confirmed pre-existing repo-wide cargo fmt drift (352 diffs on main before this change) is unrelated to this PR; only src/main.rs was modified and it was not force-reformatted to avoid touching unrelated files.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • spsprodeus21.vssps.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "spsprodeus21.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · auto · 179.6 AIC · ⌖ 11.3 AIC · ⊞ 11.1K ·

Extracted the large match over Commands variants in main() into a chain
of focused dispatcher functions (dispatch_command, handle_compile_check_mcp_command,
handle_execute_command, dispatch_lifecycle_command, handle_configure_secrets_command,
dispatch_inspect_command, handle_export_command). main() itself now only
parses args, sets up logging/update-check, and delegates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

0 participants