Skip to content

refactor(compile): use ValueEnum for the --type argument - #348

Closed
studiokvc wants to merge 1 commit into
bitcoindevkit:masterfrom
studiokvc:refactor/compile-script-type-enum
Closed

studiokvc wants to merge 1 commit into
bitcoindevkit:masterfrom
studiokvc:refactor/compile-script-type-enum

Conversation

@studiokvc

Copy link
Copy Markdown

Description

Closes #345.

CompileCommand::script_type was a String limited by value_parser, so clap already rejected anything else and the _ => arm returning "Invalid script type" was unreachable. It is now a ScriptType enum deriving clap::ValueEnum (Sh, Wsh, ShWsh, Tr), following DatabaseType in src/persister.rs, and the match is exhaustive.

Notes to the reviewers

The CLI surface is unchanged: the accepted values are still sh, wsh, sh-wsh, tr (default wsh, TYPE env var kept), an invalid value is still rejected by clap with the same list of possible values, and bdk-cli compile --help is byte-identical before and after. I left the variants without doc comments on purpose, since clap would otherwise switch the help to a per-value list.

Tests:

  • two parser unit tests: each value maps to its variant, the default is wsh, and pkh is rejected;
  • cargo test --features compiler --bins (17 passed) and the compile integration tests (cargo test --features compiler --test cli compile, 3 passed);
  • the default build (without compiler) still compiles; cargo fmt and cargo clippy --features compiler --all-targets are clean.

Checklists

All Submissions:

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

CompileCommand::script_type was a String limited by value_parser, so
clap already rejected anything else and the "Invalid script type" match
arm was unreachable. Make it a ScriptType enum deriving clap::ValueEnum,
like DatabaseType, so the match is exhaustive and the allowed values live
in one place. The accepted values (sh, wsh, sh-wsh, tr), the default and
the --help output are unchanged.

Closes bitcoindevkit#345.

Co-authored-by: Claude <noreply@anthropic.com>
@github-project-automation github-project-automation Bot moved this to Todo in BDK-CLI Oct 11, 2026
@vadim-anfv

Copy link
Copy Markdown
Collaborator

This duplicates #346, which addresses #345 with the same approach and was opened earlier.

If you'd like to help, a review on #346 would be welcome.

Closing this one as a duplicate.

@vadim-anfv vadim-anfv closed this Oct 11, 2026
@vadim-anfv vadim-anfv added the duplicate This issue or pull request already exists label Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Use ValueEnum for --type in compile command

2 participants