Skip to content

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

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-main-execute-secrets-graph-9840e52933bc65c4
Draft

refactor: reduce complexity of main() dispatch in src/main.rs#1960
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-main-execute-secrets-graph-9840e52933bc65c4

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

main() in src/main.rs was flagged by clippy::too_many_lines at 496/100 lines. It contained a large top-level match over Commands with several arms embedding substantial nested logic inline:

  • Commands::Execute { .. } — an if/else deciding between --prepare-custom-agent-output validation/materialization and normal Stage 3 safe-output execution.
  • Commands::Secrets { action } — a nested match action { Set | List | Delete } each building an options struct and dispatching.
  • Commands::Graph { subcommand } — a nested match subcommand { Dump | Deps | Outputs }.

What changed

Extracted each of these into standalone, purpose-named async helper functions so main()'s match becomes a flat, one-line-per-arm dispatch table:

  • dispatch_execute(ExecuteArgs) -> Result<()> — new ExecuteArgs struct carries the raw CLI fields; the function contains the --prepare-custom-agent-output validation/branching that was previously inline.
  • dispatch_secrets(SecretsCmd) -> Result<()> — the Set | List | Delete match, unchanged in behavior.
  • dispatch_graph_command(GraphCmd) -> Result<()> — the Dump | Deps | Outputs match, unchanged in behavior.

No public CLI behavior, flags, or error messages changed — this is purely a structural extraction to improve readability and testability.

Before / after

  • Before: main() — 496/100 lines (clippy too_many_lines).
  • After: main() — 351/100 lines (still above the 100-line lint threshold; further reduction of the remaining large match arms is left for a future pass).

Verification

  • cargo build succeeds.
  • cargo test — full suite passes, no failures.
  • 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 · 100.9 AIC · ⌖ 16.5 AIC · ⊞ 11.4K ·

Reduce cognitive complexity of main() by extracting the Commands::Execute,
Commands::Secrets, and Commands::Graph match arms into standalone async
helper functions (dispatch_execute, dispatch_secrets, dispatch_graph_command).
The top-level match in main() is now a flat one-arm-per-command dispatch
table instead of embedding nested matches and branching logic inline.
No public API or behavior changes; all existing tests pass and clippy is
clean.
Before: main() flagged by clippy::too_many_lines at 496/100 lines.
After: main() reduced to 351/100 lines (still flagged, further reduction
left for a future pass).
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 freeto 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