Skip to content

refactor(compile): use ValueEnum for script type - #346

Open
chukwudiikeh wants to merge 2 commits into
bitcoindevkit:masterfrom
chukwudiikeh:refactor/compile-script-type-enum
Open

chukwudiikeh wants to merge 2 commits into
bitcoindevkit:masterfrom
chukwudiikeh:refactor/compile-script-type-enum

Conversation

@chukwudiikeh

Copy link
Copy Markdown

Description

This PR replaces the String script_type in CompileCommand with a ScriptType enum deriving clap::ValueEnum. The goal is to make the match in execute exhaustive and keep the list of accepted script types in one place, instead of repeating it in the argument definition and in the match.

Fixes #345

Notes to the reviewers

The change is limited to src/handlers/descriptor.rs and follows the existing DatabaseType enum in src/persister.rs.

  • Added the ScriptType enum with the variants Sh, Wsh, ShWsh and Tr, gated behind the compiler feature like the rest of the compile command.
  • Changed script_type from String to ScriptType, replacing the hand-written value_parser list with value_enum.
  • The match in execute now matches on the enum variants.
  • Removed the _ => arm returning "Invalid script type", which was unreachable because clap already rejects any other value.

There is no CLI behavior change. clap renders the variants in kebab-case, so --type still accepts sh, wsh, sh-wsh and tr, the default is still wsh, and the TYPE env var still works.

I checked manually that compile --type sh-wsh produces the same descriptor before and after the change, and the existing compile tests pass.

Changelog notice

None. This is an internal refactor with no user-facing change.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Replace the String script_type in CompileCommand with a ScriptType enum deriving clap::ValueEnum. The match in execute is now exhaustive, so the unreachable fallback arm is removed. No CLI behavior change.
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.41%. Comparing base (eadbdc7) to head (36e41a3).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/handlers/descriptor.rs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #346      +/-   ##
==========================================
- Coverage   61.43%   61.41%   -0.02%     
==========================================
  Files          23       23              
  Lines        3993     3989       -4     
==========================================
- Hits         2453     2450       -3     
+ Misses       1540     1539       -1     
Flag Coverage Δ
rust 61.41% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vadim-anfv vadim-anfv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

tACK 36e41a3

Ran compile with every --type value, works as before.

Nit, non-blocking: for future commits, the body is usually wrapped at 72 chars (see the guidelines linked in CONTRIBUTING.md).

@vadim-anfv
vadim-anfv requested a review from tvpeter October 9, 2026 17:11
@chukwudiikeh

Copy link
Copy Markdown
Author

Thanks for the review and for testing, @vadim-anfv. Noted on the commit body, I'll wrap at 72 characters in future commits.

The existing compile tests only exercise wsh and tr. Add a test
for the sh and sh-wsh branches so every ScriptType variant is covered.
@chukwudiikeh

Copy link
Copy Markdown
Author

I've pushed a second commit adding a test for the sh and sh-wsh branches, to address the Codecov patch coverage report. @vadim-anfv, could you take another look when you have time?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Use ValueEnum for --type in compile command

2 participants