Skip to content

Add 'halpi usb get' subcommand for CLI compatibility #66

@mairas

Description

@mairas

Description

The Python halpi CLI supports halpi usb get as an explicit action to show USB port states. The Rust implementation only supports halpi usb (with no arguments) to achieve the same result.

Python CLI Behavior

halpi usb           # Show all port states
halpi usb get       # Show all port states (explicit action)
halpi usb enable 0  # Enable USB port 0
halpi usb disable 0 # Disable USB port 0

Current Rust CLI Behavior

halpi usb              # Show all port states ✓
halpi usb get          # ERROR: unrecognized subcommand ✗
halpi usb enable 0     # Enable USB port 0 ✓
halpi usb disable 0    # Disable USB port 0 ✓

Reference Implementation

Python implementation: HALPI2-python-daemon/src/halpi/cli.py:398-436

@app.command("usb")
def usb(
    action: str | None = typer.Argument(
        None,
        help=(
            "Action: 'get' to show port states, "
            "'enable' or 'disable' to control ports, or leave empty to show all ports"
        ),
    ),
    target: str | None = typer.Argument(
        None,
        help="Port number (0-3) or 'all' for all ports (required for enable/disable)",
    ),
) -> None:
    """Control USB port power states."""
    if action is None or action == "get":
        # Show USB port states
        ports = asyncio.run(async_get_usb_ports(state["socket"]))
        # ... display table ...

Proposed Implementation

Add a Get variant to UsbAction:

#[derive(Subcommand)]
enum UsbAction {
    /// Show USB port states
    Get,
    /// Enable a USB port (0-3 or 'all')
    Enable {
        /// Port number (0-3) or 'all'
        port: String,
    },
    /// Disable a USB port (0-3 or 'all')
    Disable {
        /// Port number (0-3) or 'all'
        port: String,
    },
}

The Get action should behave identically to calling halpi usb with no arguments.

API Compatibility

This is a minor CLI compatibility issue. While halpi usb (no args) works fine, users migrating from the Python version may expect halpi usb get to work as well.

Priority

Low - The functionality is already available via halpi usb, this is just an alias for convenience and compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions