Commit 85beba8
authored
feat(cli): add --parity and --baud-rate filters to discover command (#332)
Adds optional `--parity` and `--baud-rate` CLI parameters to the discover command that limit the serial parameters searched during device discovery, significantly reducing scan time when device configuration is known.
## Features
- `--parity <spec>`: Filter by parity modes (none, even, odd)
- `--baud-rate <spec>`: Filter by baud rates with range support
- Both support comma-separated lists and multiple flag invocations
- Automatic deduplication and standard ordering
- Comprehensive help and error messages
## Implementation
**Generic Parser Abstraction:**
- Created `parseSpec<T>()` utility eliminating code duplication
- Extracted shared `parseInteger()` helper
- Reduced parser code by ~40% while maintaining 100% coverage
**Generic Merging Utility:**
- Created `mergeSpecs<T>()` for consolidating multiple CLI flags
- Simplified discover.ts from 42 lines to 5 declarative calls
- Reusable pattern for future filters
**Architecture:**
- Filters override strategy defaults and driver config
- Type-safe generic abstractions
- Clean separation of concerns
## Testing
- 169 new tests (62 in discover command, 107 in parsers/utilities)
- 100% branch coverage for all new utilities
- 96.41% branch coverage for CLI package (exceeds 95% threshold)
- 16 E2E BATS tests for filter combinations and error handling
## Documentation
- Comprehensive discover-command.md updates
- Example 9 demonstrating performance benefits
- Inline code documentation with usage examples
## Performance Example
```bash
# Without filters: 2964 combinations (1-247 IDs × 12 rates × 1 parity)
ya-modbus discover /dev/ttyUSB0
# With filters: 5 combinations (5 IDs × 1 rate × 1 parity)
ya-modbus discover /dev/ttyUSB0 --id 1-5 --parity none --baud-rate 9600
# 99.8% reduction in search space
```1 parent f0257a2 commit 85beba8
20 files changed
Lines changed: 1824 additions & 106 deletions
File tree
- packages/cli
- docs
- src
- commands
- discovery
- utils
- tests/e2e/tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
199 | 281 | | |
200 | 282 | | |
201 | 283 | | |
| |||
205 | 287 | | |
206 | 288 | | |
207 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
208 | 293 | | |
209 | 294 | | |
210 | 295 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
68 | 92 | | |
69 | 93 | | |
70 | 94 | | |
| |||
430 | 454 | | |
431 | 455 | | |
432 | 456 | | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
433 | 488 | | |
434 | 489 | | |
435 | 490 | | |
| |||
0 commit comments