-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat: select devices to target with --device-type and --device-path arguments
#142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: select devices to target with --device-type and --device-path arguments
#142
Conversation
timrogers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loving the direction on this so far! I have a few suggestions.
|
Thanks for the review! 😄
If these changes look good, I'll fix timrogers/litra-autotoggle#48 and convert it back to a PR once it's updated accordingly. CLI Testing Output |
|
Hey @timrogers, just a friendly bump here :) |
|
Thanks for the reminder on this! I've been very busy recently but should get to it in the next couple of days. |
--all-devices and --device-type cli flags--device-type and --device-path arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for --all-devices and --device-type CLI flags to allow targeting multiple devices or specific device types, expanding the functionality beyond single device targeting by serial number.
Key changes:
- Added device filtering by type (
LitraGlow,LitraBeam,LitraBeamLX) and device path - Modified all command handlers to support targeting multiple devices when no specific filter is provided
- Enhanced MCP server integration with new device targeting options
Reviewed Changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main.rs | Core CLI implementation with new device filtering logic and multi-device command handling |
| src/lib.rs | Added DeviceType parsing, device path methods, and enhanced serial number handling |
| src/mcp.rs | Updated MCP server tools to support new device targeting parameters |
| Cargo.toml | Added schemars dependency for MCP schema generation |
| README.md | Updated documentation to reflect new device targeting options |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if use_all { | ||
| // Get all devices | ||
| let devices = get_all_supported_devices(&context, None, None, None)?; | ||
| if devices.is_empty() { | ||
| return Err(CliError::DeviceNotFound); | ||
| } | ||
|
|
||
| for device_handle in devices { | ||
| // Ignore errors for individual devices when targeting all | ||
| let _ = callback(&device_handle); | ||
| } | ||
| Ok(()) | ||
| } else { | ||
| // Filtering by one of the options | ||
| let devices = get_all_supported_devices(&context, serial_number, device_path, device_type)?; | ||
| if devices.is_empty() { | ||
| return Err(CliError::DeviceNotFound); | ||
| } | ||
|
|
||
| // Apply to all matched devices | ||
| for device_handle in devices { | ||
| // Ignore errors for individual devices | ||
| let _ = callback(&device_handle); | ||
| } | ||
| Ok(()) | ||
| } |
Copilot
AI
Aug 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic in both branches of the if-else statement is nearly identical (lines 439-448 and 451-461). This duplicated code should be extracted into a helper function or refactored to eliminate the repetition.
| if use_all { | |
| // Get all devices | |
| let devices = get_all_supported_devices(&context, None, None, None)?; | |
| if devices.is_empty() { | |
| return Err(CliError::DeviceNotFound); | |
| } | |
| for device_handle in devices { | |
| // Ignore errors for individual devices when targeting all | |
| let _ = callback(&device_handle); | |
| } | |
| Ok(()) | |
| } else { | |
| // Filtering by one of the options | |
| let devices = get_all_supported_devices(&context, serial_number, device_path, device_type)?; | |
| if devices.is_empty() { | |
| return Err(CliError::DeviceNotFound); | |
| } | |
| // Apply to all matched devices | |
| for device_handle in devices { | |
| // Ignore errors for individual devices | |
| let _ = callback(&device_handle); | |
| } | |
| Ok(()) | |
| } | |
| let (sn, dp, dt) = if use_all { | |
| (None, None, None) | |
| } else { | |
| (serial_number, device_path, device_type) | |
| }; | |
| let devices = get_all_supported_devices(&context, sn, dp, dt)?; | |
| if devices.is_empty() { | |
| return Err(CliError::DeviceNotFound); | |
| } | |
| for device_handle in devices { | |
| // Ignore errors for individual devices | |
| let _ = callback(&device_handle); | |
| } | |
| Ok(()) |
src/lib.rs
Outdated
| let s_lower = s.to_lowercase().replace(" ", ""); | ||
| match s_lower.as_str() { | ||
| "litra_glow" | "glow" => Ok(DeviceType::LitraGlow), | ||
| "litra_beam" | "beam" => Ok(DeviceType::LitraBeam), | ||
| "litra_beam_lx" | "beam_lx" => Ok(DeviceType::LitraBeamLX), |
Copilot
AI
Aug 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string matching patterns use underscores (e.g., 'litra_beam_lx') but the help text and documentation mention 'LitraBeamLX' without underscores. Consider supporting both formats or clarifying the expected input format in documentation.
| let s_lower = s.to_lowercase().replace(" ", ""); | |
| match s_lower.as_str() { | |
| "litra_glow" | "glow" => Ok(DeviceType::LitraGlow), | |
| "litra_beam" | "beam" => Ok(DeviceType::LitraBeam), | |
| "litra_beam_lx" | "beam_lx" => Ok(DeviceType::LitraBeamLX), | |
| // Normalize: lowercase, remove spaces and underscores | |
| let s_norm = s.to_lowercase().replace([' ', '_'], ""); | |
| match s_norm.as_str() { | |
| "litraglow" | "glow" => Ok(DeviceType::LitraGlow), | |
| "litrabeam" | "beam" => Ok(DeviceType::LitraBeam), | |
| "litrabeamlx" | "beamlx" => Ok(DeviceType::LitraBeamLX), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Compiled on linux (via WSL) and Windows and tested on Windows with a Litra Beam LX and a Litra Glow. All commands worked as expected.
Fixes #133
CLI Testing Output