Add --host-command to send raw EC host commands#268
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a --host-command CLI option to send arbitrary Chromium EC host commands (ID, version, optional payload) and print the raw response, primarily for debugging new/unsupported EC commands.
Changes:
- Replaces the unimplemented
raw_commandCLI field withhost_command: Option<(u16, u8, Vec<u8>)>and wires it into execution viaec.send_command(...). - Implements parsing for
--host-commandin both UEFI argument parsing and the clap-based CLI. - Updates shell completions and advanced examples documentation to include
--host-command.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| framework_lib/src/commandline/uefi.rs | Adds UEFI-shell parsing for --host-command, including hex/dec parsing helpers. |
| framework_lib/src/commandline/mod.rs | Adds host_command to Cli and dispatches it to ec.send_command. |
| framework_lib/src/commandline/clap_std.rs | Adds clap definition + conversion logic for --host-command. |
| completions/zsh/_framework_tool | Adds zsh completion entry for --host-command. |
| completions/fish/framework_tool.fish | Adds fish completion entry for --host-command. |
| completions/bash/framework_tool | Adds bash completion flag for --host-command. |
| EXAMPLES_ADVANCED.md | Documents usage and shows example outputs for raw EC host commands. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else if let Some((command_id, command_version, ref data)) = args.host_command { | ||
| match ec.send_command(command_id, command_version, data) { |
There was a problem hiding this comment.
args is a shared reference (&Cli), but this pattern matches on args.host_command by value, which attempts to move the Option<(u16, u8, Vec<u8>)> out of a borrowed struct and won’t compile. Match on a reference instead (e.g. via args.host_command.as_ref() / &args.host_command) and borrow the payload bytes when calling send_command.
| } else if let Some((command_id, command_version, ref data)) = args.host_command { | |
| match ec.send_command(command_id, command_version, data) { | |
| } else if let Some((command_id, command_version, data)) = args.host_command.as_ref() { | |
| match ec.send_command(*command_id, *command_version, data) { |
There was a problem hiding this comment.
won’t compile
no it does build
| if let Some(byte) = parse_hex_or_dec_u8(&args[j]) { | ||
| data.push(byte); | ||
| } else { | ||
| println!("Invalid data byte for --host-command: '{}'", args[j]); | ||
| break; | ||
| } | ||
| } | ||
| Some((cmd_id, version, data)) | ||
| } else { |
There was a problem hiding this comment.
When an invalid payload byte is encountered, the code prints an error and breaks, but still returns Some((cmd_id, version, data)) and will proceed to send a truncated payload. Treat any invalid byte as a hard parse failure for --host-command (return None / clear cli.host_command) so you don’t accidentally send a different command than intended.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
| return 0 | ||
| ;; | ||
| --host-command) | ||
| COMPREPLY=($(compgen -f "${cur}")) |
There was a problem hiding this comment.
The bash completion treats --host-command like it expects a filename (compgen -f). This produces irrelevant suggestions and can be confusing since the arguments are numeric bytes/IDs. Remove the file completion for this flag (or provide numeric hints if desired).
| COMPREPLY=($(compgen -f "${cur}")) | |
| COMPREPLY=() |
There was a problem hiding this comment.
Are you sure? clap generates it like this
There was a problem hiding this comment.
hmm, other commands also have this problem, let's debug this later
There was a problem hiding this comment.
|
@JohnAZoidberg I've opened a new pull request, #269, to work on those changes. Once the pull request is ready, I'll request review from you. |
b795c8a to
37663cb
Compare
Useful for debugging new host commands Signed-off-by: Daniel Schaefer <dhs@frame.work>
37663cb to
3f79e0a
Compare
Useful for debugging new host commands