Repository navigation
Commit fe89838
committed
Merge #346: refactor(compile): use ValueEnum for script type
79b2b83 test(compile): cover sh and sh-wsh script types (Ikeh Celestine Chukwudi)
36e41a3 refactor(compile): use ValueEnum for script type (Ikeh Celestine Chukwudi)
Pull request description:
### 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:
* [x] I've signed all my commits
* [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk-cli/blob/master/CONTRIBUTING.md)
* [x] I ran `cargo fmt` and `cargo clippy` before committing
ACKs for top commit:
tvpeter:
ACK 79b2b83
Tree-SHA512: cb8ab8fef5d109149740f22c20d6bee768079d082f3f84b7cb80541b605b66f2235d386ff080d4e31b24285a8e7935ab87deeae500abf9895f91d766226ba5002 files changed
Lines changed: 45 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
73 | | - | |
74 | | - | |
75 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
76 | 93 | | |
77 | 94 | | |
78 | 95 | | |
| |||
87 | 104 | | |
88 | 105 | | |
89 | 106 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
95 | 112 | | |
96 | 113 | | |
97 | 114 | | |
| |||
113 | 130 | | |
114 | 131 | | |
115 | 132 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | 133 | | |
122 | 134 | | |
123 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
226 | 246 | | |
227 | 247 | | |
228 | 248 | | |
| |||
0 commit comments