refactor: reduce complexity of main() dispatch in src/main.rs - #1868
Draft
github-actions[bot] wants to merge 1 commit into
Draft
refactor: reduce complexity of main() dispatch in src/main.rs#1868github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
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: 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. |
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
async fn main()insrc/main.rswas flagged byclippy::too_many_linesat 492/100 lines. It contained a single giantmatch 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 (viahandle_compile_check_mcp_command), McpAuthor (inline), Execute (viahandle_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-outputlogic).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, calldispatch_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
main()at 492 lines.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.cargo fmtdrift (352 diffs onmainbefore this change) is unrelated to this PR; onlysrc/main.rswas 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.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.