Skip to content

refactor(cli): split main() dispatch into per-group helper functions - #1999

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

refactor(cli): split main() dispatch into per-group helper functions#1999
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-main-dispatch-3-cbfa8390dee89b16

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

main() in src/main.rs had grown to a single match on Commands spanning ~355 lines (Clippy too_many_lines threshold is 100), handling every CLI subcommand's dispatch logic inline: Compile, Check, Mcp, McpAuthor, Execute, Init, Configure, Secrets (with a nested match), Enable, Disable, Remove, List, Status, Run, Audit, Trace, five Export* commands, Inspect, Graph (nested match), Whatif, Lint, and Catalog.

What changed

Extracted four groups of match arms into standalone async/sync helper functions, each owning a cohesive slice of dispatch logic:

  • dispatch_secrets_command(action: SecretsCmd) — the Secrets::{Set,List,Delete} nested match.
  • dispatch_lifecycle_command(command: Commands)Enable, Disable, Remove, List, Status, Run, Audit, Trace (all share the same org/project/pat/path REST-client shape).
  • dispatch_export_command(command: Commands) — the five hidden build-time Export* commands (all synchronous generate-and-write/print operations).
  • dispatch_inspect_group_command(command: Commands)Inspect, Graph, Whatif, Lint, Catalog (read-only static-analysis commands over the compiled IR).

main() now matches on Commands and calls into these helpers for the extracted groups, keeping Compile, Check, Mcp, McpAuthor, Execute, Init, and Configure inline since they have distinct pre/post logic (guards, background update-check spawn, etc.).

No public API or observable behavior changes — every arm's body was moved verbatim into its new helper.

Before/after complexity

  • Before: main() — 355 lines (clippy::too_many_lines, threshold 100)
  • After: main() — 186 lines (clippy::too_many_lines); still above the lint threshold but roughly halved, and each extracted helper is a focused, independently readable/testable unit (dispatch_lifecycle_command is the largest new helper).

Verification

  • cargo build --bin ado-aw — clean
  • cargo test — full suite passes (all packages/binaries)
  • cargo clippy --all-targets --all-features — clean (one pre-existing, unrelated warning in create_work_item.rs)

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 · 92.3 AIC · ⌖ 10 AIC · ⊞ 11.4K ·

Extracts the Secrets, lifecycle (Enable/Disable/Remove/List/Status/Run/
Audit/Trace), export (ExportGateSchema/ExportFactCatalog/
ExportAdoProxyCatalog{,Schema}/ExportBashScripts), and inspect-group
(Inspect/Graph/Whatif/Lint/Catalog) match arms out of main() into
dispatch_secrets_command, dispatch_lifecycle_command,
dispatch_export_command, and dispatch_inspect_group_command.

No public API or behavior changes. main() shrinks from 355 to 186
lines (too_many_lines); full test suite and clippy --all-targets
--all-features pass clean.

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