Repository navigation
refactor(clip): use ClippingMode enum instead of String for --clipping-mode - #218
Conversation
…g-mode Derive clap::ValueEnum on ClippingMode so clap handles parsing and validation at argument-parse time. This removes two manual match blocks in clip.rs, eliminates the possibility of runtime "invalid clipping mode" errors, and gives users automatic shell completions and help text for the valid variants.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #218 +/- ##
==========================================
- Coverage 88.07% 88.06% -0.02%
==========================================
Files 113 113
Lines 52863 52816 -47
==========================================
- Hits 46561 46511 -50
- Misses 6302 6305 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📝 WalkthroughWalkthroughThe changes add 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/commands/clip.rs (1)
1081-1108: Parameterize the enum-mode test withrstest.This test currently checks one case and is a good fit for
rstestcases over all variants.♻️ Suggested refactor
- #[test] - fn test_clipping_mode_enum_values() { - // Test that clipping_mode enum variants are set properly - let soft = Clip { + #[rstest] + #[case(ClippingMode::Soft)] + #[case(ClippingMode::SoftWithMask)] + #[case(ClippingMode::Hard)] + fn test_clipping_mode_enum_values(#[case] mode: ClippingMode) { + let clip = Clip { io: BamIoOptions { input: PathBuf::from("input.bam"), output: PathBuf::from("output.bam"), }, reference: PathBuf::from("reference.fa"), - clipping_mode: ClippingMode::Soft, + clipping_mode: mode, clip_overlapping_reads: true, clip_extending_past_mate: false, @@ scheduler_opts: SchedulerOptions::default(), queue_memory: QueueMemoryOptions::default(), }; - assert_eq!(soft.clipping_mode, ClippingMode::Soft); + assert_eq!(clip.clipping_mode, mode); }As per coding guidelines "
**/*.rs: Use rstest for parameterized tests".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/clip.rs` around lines 1081 - 1108, Replace the single-case test_clipping_mode_enum_values with an rstest-parameterized test: add the #[rstest] attribute (and import rstest::rstest) and change the function signature to accept a clipping_mode: ClippingMode parameter with a #[case(...)] for each ClippingMode variant; inside the test construct the Clip using that clipping_mode (same construction as before) and assert_eq!(clipping_mode, clip.clipping_mode). Keep the test name (test_clipping_mode_enum_values) and reference the Clip struct and ClippingMode enum so the IDE can locate the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/commands/clip.rs`:
- Around line 1081-1108: Replace the single-case test_clipping_mode_enum_values
with an rstest-parameterized test: add the #[rstest] attribute (and import
rstest::rstest) and change the function signature to accept a clipping_mode:
ClippingMode parameter with a #[case(...)] for each ClippingMode variant; inside
the test construct the Clip using that clipping_mode (same construction as
before) and assert_eq!(clipping_mode, clip.clipping_mode). Keep the test name
(test_clipping_mode_enum_values) and reference the Clip struct and ClippingMode
enum so the IDE can locate the code.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: eecbaf1d-a2b4-4854-932b-02fd7e34f098
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (3)
crates/fgumi-sam/Cargo.tomlcrates/fgumi-sam/src/clipper.rssrc/commands/clip.rs
Summary
clap::ValueEnumon the existingClippingModeenum so that clap validates the--clipping-modeargument at parse time instead of at runtimematch self.clipping_mode.as_str()blocks inclip.rs(one inexecute(), one in the pipeline closure)clipping_modefield type fromStringtoClippingModein theClipCLI structDisplayimpl onClippingModefor the info log linetest_clip_execute_invalid_clipping_modetest (invalid values are rejected by clap at parse time)Test plan
cargo ci-fmtpassescargo ci-lintpassescargo nextest run --no-fail-fast— 1734 tests pass, 7 skippedfgumi clip --helpshows the valid values for--clipping-modefgumi clip --clipping-mode invalid ...is rejected by clap with a helpful error