Skip to content

refactor(main): extract execute/secrets/graph dispatch from main() - #1972

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

refactor(main): extract execute/secrets/graph dispatch from main()#1972
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-main-execute-secrets-graph-2-b3d7ef883133baa7

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

main() in src/main.rs was flagged by Clippy's too_many_lines lint at 496/100 lines. The bulk of this was three large match arms handling Commands::Execute, Commands::Secrets, and Commands::Graph, each containing substantial inline logic (including a nested match for Commands::Secrets's SecretsCmd and Commands::Graph's GraphCmd).

What changed

Extracted the logic for these three arms into standalone async helper functions, placed just above main():

  • dispatch_execute_command(ExecuteCommandArgs) -> Result<()> — handles the --prepare-custom-agent-output branch and the normal run_execute path. New ExecuteCommandArgs struct groups the CLI-parsed fields.
  • dispatch_secrets_command(SecretsCmd) -> Result<()> — handles SecretsCmd::Set / List / Delete.
  • dispatch_graph_command(GraphCmd) -> Result<()> — handles GraphCmd::Dump / Deps / Outputs.

main()'s top-level match now has a single, flat call per arm for these commands, matching the pattern already used elsewhere in the file (e.g. run_execute, run_compile).

Result

  • main() cognitive/line complexity: 496/100 → 355/100 (still above the artificially low 100-line Clippy threshold used to surface candidates, but a meaningful reduction; a further pass could extract more arms).
  • No public API or CLI behavior changes.
  • cargo build, cargo test (full suite), and cargo clippy --all-targets --all-features all pass clean (one pre-existing, unrelated field_reassign_with_default warning in create_work_item.rs remains untouched).

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 · 120.6 AIC · ⌖ 5.62 AIC · ⊞ 11.4K ·

Extracts the Commands::Execute, Commands::Secrets, and Commands::Graph
match arms from main() into standalone async helper functions
(dispatch_execute_command, dispatch_secrets_command,
dispatch_graph_command). main()'s too_many_lines complexity drops from
496 to 355. No public API or behavior changes; 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 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