Skip to content

Refactor build CLI into dedicated args#66

Merged
leynos merged 2 commits intomainfrom
codex/refactor-cli-to-use-buildargs-struct
Aug 6, 2025
Merged

Refactor build CLI into dedicated args#66
leynos merged 2 commits intomainfrom
codex/refactor-cli-to-use-buildargs-struct

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Aug 6, 2025

Summary

  • model build subcommand with BuildArgs struct and explicit --emit
  • adjust runner and tests for new Commands::Build(BuildArgs) pattern
  • document revised CLI in design notes

Testing

  • make fmt
  • make lint
  • make test
  • make markdownlint
  • ./target/debug/netsuke --file tests/data/minimal.yml --verbose build --emit /tmp/out.ninja hello

https://chatgpt.com/codex/tasks/task_e_68930362753c832284a53f268ffc83bd

Summary by Sourcery

Refactor the build subcommand to use a dedicated BuildArgs struct and update corresponding CLI parsing, runner logic, tests, and documentation to match the new pattern.

Enhancements:

  • Extract BuildArgs struct to encapsulate build command options and convert Commands::Build to use it
  • Adjust CLI defaulting logic and runner matching to the new Commands::Build(BuildArgs) pattern

Documentation:

  • Update netsuke-design.md to document the new BuildArgs structure in the CLI specification

Tests:

  • Revise unit and Cucumber tests to reference BuildArgs in build command definitions

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Aug 6, 2025

Reviewer's Guide

Extract build subcommand arguments into a dedicated BuildArgs struct and propagate the new Commands::Build(BuildArgs) signature throughout the runner, documentation, and tests.

Class diagram for refactored CLI command structure

classDiagram
    Cli "1" -- "0..1" Commands : command
    Commands <|-- BuildArgs
    class Cli {
        +Option<Commands> command
    }
    class Commands {
        <<enum>>
        +Build(BuildArgs)
        +Clean
        +Graph
        +Manifest
    }
    class BuildArgs {
        +Option<PathBuf> emit
        +Vec<String> targets
    }
Loading

File-Level Changes

Change Details Files
Extract build command arguments into a separate BuildArgs struct
  • Define BuildArgs with emit and targets fields using clap::Args
  • Change Commands::Build variant to wrap BuildArgs
  • Adjust default command initialization to instantiate BuildArgs
src/cli.rs
docs/netsuke-design.md
Adapt runner logic to the new BuildArgs-based Build command
  • Update default command unwrap to use Build(BuildArgs)
  • Match Commands::Build(args) and use args.emit and args.targets
src/runner.rs
Update tests to use BuildArgs in Commands::Build
  • Import BuildArgs in test modules
  • Wrap test command initialization in Commands::Build(BuildArgs { … })
  • Adjust pattern matching in CLI step definitions and runner tests
tests/runner_tests.rs
tests/steps/cli_steps.rs
tests/cli_tests.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 6, 2025

Summary by CodeRabbit

  • Refactor
    • Improved the structure of the build command in the CLI by encapsulating its arguments within a dedicated BuildArgs struct, enhancing modularity and clarity.
    • Updated related test cases and documentation to align with the new command structure.
    • Minor formatting and import adjustments for consistency.

Walkthrough

Refactor the CLI command structure by extracting the Build command's parameters into a new BuildArgs struct. Update all code, tests, and documentation to use this struct instead of inline fields. Adjust pattern matching, imports, and documentation to match the new structure. No external behaviour or logic is changed.

Changes

Cohort / File(s) Change Summary
Documentation Update
docs/netsuke-design.md
Refactor CLI command documentation: describe BuildArgs struct, update Commands enum variants, and tidy imports.
CLI Structure Refactor
src/cli.rs
Extract BuildArgs struct for build command parameters, update Commands enum, and adjust imports.
Runner Adaptation
src/runner.rs
Update pattern matching and comments to use BuildArgs with Commands::Build.
CLI Tests Update
tests/cli_tests.rs
Replace inline Build command construction with BuildArgs struct in all relevant tests.
Runner Tests Update
tests/runner_tests.rs
Update test setup and imports to use BuildArgs with Commands::Build.
Step Definitions Update
tests/steps/cli_steps.rs
Update imports, pattern matching, and command construction to use BuildArgs struct.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant BuildArgs
    participant Runner

    User->>CLI: Invoke build command with arguments
    CLI->>BuildArgs: Parse build arguments into BuildArgs struct
    CLI->>Runner: Pass Commands::Build(BuildArgs)
    Runner->>BuildArgs: Access emit and targets fields
    Runner-->>User: Execute build process and return result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Implement initial CLI #20: This PR builds directly upon the CLI definitions introduced in the initial implementation, refactoring the Build command structure.
  • Generate Ninja build file on the fly #55: Adds new CLI options and subcommands including an emit field but does not modularize the Build variant into a separate struct; related but distinct focus.

Poem

A struct for build, so neat and new,
Refactored fields, a cleaner view!
Tests and docs all join the dance,
With pattern matches in advance.
No logic changed, just tidied code—
March on, maintainers, down this road!
🦀✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d5ea1e and f0843fe.

📒 Files selected for processing (1)
  • docs/netsuke-design.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
docs/**/*.md

📄 CodeRabbit Inference Engine (AGENTS.md)

docs/**/*.md: Use the markdown files within the docs/ directory as a knowledge base and source of truth for project requirements, dependency choices, and architectural decisions.
Proactively update the relevant file(s) in the docs/ directory to reflect the latest state when new decisions are made, requirements change, libraries are added/removed, or architectural patterns evolve.

Files:

  • docs/netsuke-design.md
**/*.md

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.md: Documentation must use en-GB-oxendict spelling and grammar, except for the naming of the "LICENSE" file.
Validate Markdown files using make markdownlint.
Run make fmt after any documentation changes to format all Markdown files and fix table markup.
Validate Mermaid diagrams in Markdown files by running make nixie.
Markdown paragraphs and bullet points must be wrapped at 80 columns.
Code blocks in Markdown must be wrapped at 120 columns.
Tables and headings in Markdown must not be wrapped.
Use dashes (-) for list bullets in Markdown.
Use GitHub-flavoured Markdown footnotes ([^1]) for references and footnotes.

Files:

  • docs/netsuke-design.md

⚙️ CodeRabbit Configuration File

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-GB-oxendict (-ize / -our) spelling and grammar
  • Paragraphs and bullets must be wrapped to 80 columns, except where a long URL would prevent this (in which case, silence MD013 for that line)
  • Code blocks should be wrapped to 120 columns.
  • Headings must not be wrapped.
  • Documents must start with a level 1 heading
  • Headings must correctly increase or decrease by no more than one level at a time
  • Use GitHub-flavoured Markdown style for footnotes and endnotes.
  • Numbered footnotes must be numbered by order of appearance in the document.

Files:

  • docs/netsuke-design.md
🔇 Additional comments (4)
docs/netsuke-design.md (4)

1351-1351: Split-import issue resolved – good.

The use line now imports only clap items, removing the prior combined path.
No further action required.


1378-1385: Enum variants are now compile-ready.

Clean and Graph switch to unit variants, eliminating the stray braces that
previously broke the example. Nice fix.


1389-1395: Manifest variant reads cleanly.

The inline struct for Manifest is syntactically correct and illustrative.
No issues spotted.


1397-1405: Struct formatting issue fixed.

BuildArgs now separates doc comments from fields and closes with its own
brace, so the snippet compiles as-is.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/refactor-cli-to-use-buildargs-struct

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Aug 6, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 6, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3ec2aa and 5d5ea1e.

📒 Files selected for processing (6)
  • docs/netsuke-design.md (2 hunks)
  • src/cli.rs (2 hunks)
  • src/runner.rs (3 hunks)
  • tests/cli_tests.rs (1 hunks)
  • tests/runner_tests.rs (5 hunks)
  • tests/steps/cli_steps.rs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • tests/cli_tests.rs
  • src/runner.rs
  • src/cli.rs
  • tests/runner_tests.rs
  • tests/steps/cli_steps.rs
**/*.md

⚙️ CodeRabbit Configuration File

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-GB-oxendict (-ize / -our) spelling and grammar
  • Paragraphs and bullets must be wrapped to 80 columns, except where a long URL would prevent this (in which case, silence MD013 for that line)
  • Code blocks should be wrapped to 120 columns.
  • Headings must not be wrapped.
  • Documents must start with a level 1 heading
  • Headings must correctly increase or decrease by no more than one level at a time
  • Use GitHub-flavoured Markdown style for footnotes and endnotes.
  • Numbered footnotes must be numbered by order of appearance in the document.

Files:

  • docs/netsuke-design.md
🧬 Code Graph Analysis (1)
tests/runner_tests.rs (1)
tests/steps/cli_steps.rs (1)
  • emit_path (140-143)
🔇 Additional comments (18)
src/cli.rs (4)

6-6: Import addition looks correct.

The Args import is properly added to support the new BuildArgs struct.


83-92: Well-structured argument encapsulation.

The BuildArgs struct properly encapsulates build command arguments with appropriate derives and documentation. The field structure matches the previous inline implementation.


98-98: Clean enum variant refactor.

The Commands::Build variant now properly wraps BuildArgs, maintaining the same functionality whilst improving modularity.


74-77: Default command construction updated correctly.

The default command construction properly uses the new BuildArgs struct with appropriate field initialization.

tests/cli_tests.rs (2)

7-7: Import updated appropriately.

The BuildArgs import correctly supports the refactored test construction patterns.


12-28: Test cases properly updated for new structure.

All Commands::Build constructions correctly use the BuildArgs wrapper whilst maintaining the same test coverage and assertions.

tests/steps/cli_steps.rs (3)

9-9: Import addition supports refactored structure.

The BuildArgs import correctly enables the updated cucumber step implementations.


19-22: Default command construction updated properly.

The fallback default command correctly uses the BuildArgs struct with appropriate field initialization.


37-37: Pattern matching updated correctly.

The destructuring pattern properly accesses the BuildArgs fields through the struct wrapper, maintaining the same extraction logic.

tests/runner_tests.rs (5)

1-1: Import updated to support refactored tests.

The BuildArgs import correctly enables the updated test construction patterns throughout the file.


19-22: Test construction properly refactored.

The Commands::Build construction correctly uses BuildArgs wrapper whilst maintaining identical test behavior.


38-41: Consistent refactoring across test functions.

All test functions properly adopt the BuildArgs structure, maintaining test integrity and coverage.


74-77: Build command construction remains functionally identical.

The refactored construction maintains the same test scenarios whilst using the new BuildArgs encapsulation.


114-117: Emit functionality test properly updated.

The test correctly constructs Commands::Build with the emit path specified in the BuildArgs struct, maintaining the same test logic.

src/runner.rs (4)

7-7: Import supports refactored CLI handling.

The BuildArgs import correctly enables the updated command processing logic.


72-75: Default command fallback properly updated.

The default command construction correctly uses the BuildArgs struct with appropriate field initialization.


77-80: Command processing logic correctly refactored.

The pattern matching and field access properly adapt to the BuildArgs structure whilst maintaining identical runtime behavior.


143-143: Documentation example updated appropriately.

The doc comment example correctly reflects the new BuildArgs usage, maintaining accurate documentation.

Comment thread docs/netsuke-design.md Outdated
Comment thread docs/netsuke-design.md
Comment thread docs/netsuke-design.md Outdated
@leynos leynos merged commit 4aefa8f into main Aug 6, 2025
3 of 4 checks passed
@leynos leynos deleted the codex/refactor-cli-to-use-buildargs-struct branch August 6, 2025 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant