From 466159fa2331eb21079f8ae384a2c195b18ff1b1 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 26 Jan 2026 13:15:06 +0800 Subject: [PATCH 1/3] Generate shell auto completions using clap_complete So that they don't become outdated by having to manually update them. Also allows more easily adding more shells. Signed-off-by: Daniel Schaefer --- Cargo.lock | 10 ++++++++++ framework_lib/Cargo.toml | 2 ++ framework_lib/src/commandline/clap_std.rs | 17 +++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index eff80f59..b05b2ec6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,6 +196,15 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.5.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "430b4dc2b5e3861848de79627b2bedc9f3342c7da5173a14eaa5d0f8dc18ae5d" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.5.49" @@ -408,6 +417,7 @@ dependencies = [ "clap", "clap-num", "clap-verbosity-flag", + "clap_complete", "env_logger", "guid-create", "hidapi", diff --git a/framework_lib/Cargo.toml b/framework_lib/Cargo.toml index 0ec2e522..3ab8a043 100644 --- a/framework_lib/Cargo.toml +++ b/framework_lib/Cargo.toml @@ -50,6 +50,7 @@ env_logger = "0.11" clap = { version = "4.5", features = ["derive", "cargo"] } clap-num = { version = "1.2.0" } clap-verbosity-flag = { version = "3.0" } +clap_complete = "4.5" windows-version = "0.1.4" winreg = "0.55.0" nvml-wrapper = { version = "0.11.0", optional = true } @@ -63,6 +64,7 @@ env_logger = "0.11" clap = { version = "4.5", features = ["derive", "cargo"] } clap-num = { version = "1.2.0" } clap-verbosity-flag = { version = "3.0" } +clap_complete = "4.5" nvml-wrapper = { version = "0.11.0", optional = true } [target.'cfg(windows)'.dependencies.windows] diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 3952675e..25a34a5f 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -1,9 +1,12 @@ //! Module to factor out commandline interaction //! This way we can use it in the regular OS commandline tool on Linux and Windows, //! as well as on the UEFI shell tool. +use std::io; + use clap::error::ErrorKind; use clap::Parser; use clap::{command, Arg, Args, FromArgMatches}; +use clap_complete::{generate, Shell}; use clap_num::maybe_hex; use crate::chromium_ec::commands::SetGpuSerialMagic; @@ -296,6 +299,10 @@ struct ClapCli { /// Show NVIDIA GPU information (Framework 16 only) #[arg(long)] nvidia: bool, + + /// Generate shell completions and print to stdout + #[arg(long, value_name = "SHELL", hide = true)] + generate_completions: Option, } /// Parse a list of commandline arguments and return the struct @@ -307,6 +314,16 @@ pub fn parse(args: &[String]) -> Cli { // Step 2 - Define args from derived struct let mut cli = ClapCli::augment_args(cli); + // Handle --generate-completions early (generates and exits) + if let Some(shell_arg) = args.iter().position(|a| a == "--generate-completions") { + if let Some(shell_str) = args.get(shell_arg + 1) { + if let Ok(shell) = shell_str.parse::() { + generate(shell, &mut cli, "framework_tool", &mut io::stdout()); + std::process::exit(0); + } + } + } + // Step 3 - Parse args that can't be derived let matches = cli.clone().get_matches_from(args); let fgd = matches From 7d29c9bfadae95b84f0f0ade66456f03c95145dd Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 26 Jan 2026 13:15:51 +0800 Subject: [PATCH 2/3] completions: Update all shells and add more Signed-off-by: Daniel Schaefer --- completions/README.md | 54 +++++ completions/bash/framework_tool | 289 +++++++++++++++++++-------- completions/fish/framework_tool.fish | 98 +++++++++ completions/zsh/_framework_tool | 153 +++++++++----- 4 files changed, 463 insertions(+), 131 deletions(-) create mode 100644 completions/README.md create mode 100644 completions/fish/framework_tool.fish diff --git a/completions/README.md b/completions/README.md new file mode 100644 index 00000000..c957a126 --- /dev/null +++ b/completions/README.md @@ -0,0 +1,54 @@ +# Shell Completions + +Shell completions for `framework_tool` are auto-generated using `clap_complete`. + +## Regenerating + +If you modify the CLI arguments, regenerate completions: + +```bash +cargo build +./target/debug/framework_tool --generate-completions bash > completions/bash/framework_tool +./target/debug/framework_tool --generate-completions zsh > completions/zsh/_framework_tool +./target/debug/framework_tool --generate-completions fish > completions/fish/framework_tool.fish +``` + +## Testing + +`framework_tool` must be in your PATH for completions to work. + +**Bash:** +```bash +export PATH="$PWD/target/debug:$PATH" +source completions/bash/framework_tool +framework_tool -- +``` + +**Zsh:** +```zsh +export PATH="$PWD/target/debug:$PATH" +source completions/zsh/_framework_tool +framework_tool -- +``` + +**Fish:** +```fish +fish_add_path $PWD/target/debug +source completions/fish/framework_tool.fish +framework_tool -- +``` + +**PowerShell:** +```powershell +framework_tool --generate-completions powershell | Invoke-Expression +framework_tool -- +``` + +## Persistent Installation + +Linux: Should be done by downstream package maintainers. + +Windows/PowerShell: +```powershell +framework_tool --generate-completions powershell >> $PROFILE +``` diff --git a/completions/bash/framework_tool b/completions/bash/framework_tool index 7031b8d5..c79d73e4 100755 --- a/completions/bash/framework_tool +++ b/completions/bash/framework_tool @@ -1,85 +1,214 @@ -#!/usr/bin/env bash - -# Bash completion for framework_tool - _framework_tool() { - local options - options=( - "--flash-gpu-descriptor" - "-v" "--verbose" - "-q" "--quiet" - "--versions" - "--version" - "--features" - "--esrt" - "--device" - "--compare-version" - "--power" - "--thermal" - "--sensors" - "--pdports" - "--info" - "--pd-info" - "--dp-hdmi-info" - "--dp-hdmi-update" - "--audio-card-info" - "--privacy" - "--pd-bin" - "--ec-bin" - "--capsule" - "--dump" - "--ho2-capsule" - "--dump-ec-flash" - "--flash-ec" - "--flash-ro-ec" - "--flash-rw-ec" - "--intrusion" - "--inputdeck" - "--inputdeck-mode" - "--charge-limit" - "--get-gpio" - "--fp-led-level" - "--fp-brightness" - "--kblight" - "--rgbkbd" - "--tablet-mode" - "--touchscreen-enable" - "--console" - "--reboot-ec" - "--hash" - "--driver" - "--pd-addrs" - "--pd-ports" - "-t" "--test" - "-h" "--help" - ) - - local devices=("bios" "ec" "pd0" "pd1" "rtm01" "rtm23" "ac-left" "ac-right") - local inputdeck_modes=("auto" "off" "on") - local console_modes=("recent" "follow") - local drivers=("portio" "cros-ec" "windows") - local brightness_options=("high" "medium" "low" "ultra-low") - - local current_word prev_word - current_word="${COMP_WORDS[COMP_CWORD]}" - prev_word="${COMP_WORDS[COMP_CWORD-1]}" - - # Handle options - if [[ $COMP_CWORD -eq 1 ]]; then - COMPREPLY=( $(compgen -W "${options[*]}" -- "$current_word") ) - elif [[ $prev_word == "--device" ]]; then - COMPREPLY=( $(compgen -W "${devices[*]}" -- "$current_word") ) - elif [[ $prev_word == "--inputdeck-mode" ]]; then - COMPREPLY=( $(compgen -W "${inputdeck_modes[*]}" -- "$current_word") ) - elif [[ $prev_word == "--console" ]]; then - COMPREPLY=( $(compgen -W "${console_modes[*]}" -- "$current_word") ) - elif [[ $prev_word == "--driver" ]]; then - COMPREPLY=( $(compgen -W "${drivers[*]}" -- "$current_word") ) - elif [[ $prev_word == "--fp-brightness" ]]; then - COMPREPLY=( $(compgen -W "${brightness_options[*]}" -- "$current_word") ) + local i cur prev opts cmd + COMPREPLY=() + if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then + cur="$2" + else + cur="${COMP_WORDS[COMP_CWORD]}" fi + prev="$3" + cmd="" + opts="" + + for i in "${COMP_WORDS[@]:0:COMP_CWORD}" + do + case "${cmd},${i}" in + ",$1") + cmd="framework_tool" + ;; + *) + ;; + esac + done - return 0 + case "${cmd}" in + framework_tool) + opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --thermal --sensors --fansetduty --fansetrpm --autofanctrl --pdports --info --pd-info --pd-reset --pd-disable --pd-enable --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --stylus-battery --console --reboot-ec --ec-hib-delay --uptimeinfo --s0ix-counter --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --nvidia --generate-completions --help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + --flash-gpu-descriptor) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --device) + COMPREPLY=($(compgen -W "bios ec pd0 pd1 rtm01 rtm23 ac-left ac-right" -- "${cur}")) + return 0 + ;; + --compare-version) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --fansetduty) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --fansetrpm) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --autofanctrl) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --pd-reset) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --pd-disable) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --pd-enable) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --dp-hdmi-update) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --pd-bin) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --ec-bin) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --capsule) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --dump) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --h2o-capsule) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --dump-ec-flash) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --flash-ec) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --flash-ro-ec) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --flash-rw-ec) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --inputdeck-mode) + COMPREPLY=($(compgen -W "auto off on" -- "${cur}")) + return 0 + ;; + --charge-limit) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --charge-current-limit) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --charge-rate-limit) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --get-gpio) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --fp-led-level) + COMPREPLY=($(compgen -W "high medium low ultra-low auto" -- "${cur}")) + return 0 + ;; + --fp-brightness) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --kblight) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --remap-key) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --rgbkbd) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --ps2-enable) + COMPREPLY=($(compgen -W "true false" -- "${cur}")) + return 0 + ;; + --tablet-mode) + COMPREPLY=($(compgen -W "auto tablet laptop" -- "${cur}")) + return 0 + ;; + --touchscreen-enable) + COMPREPLY=($(compgen -W "true false" -- "${cur}")) + return 0 + ;; + --console) + COMPREPLY=($(compgen -W "recent follow" -- "${cur}")) + return 0 + ;; + --reboot-ec) + COMPREPLY=($(compgen -W "reboot jump-ro jump-rw cancel-jump disable-jump" -- "${cur}")) + return 0 + ;; + --ec-hib-delay) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --hash) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --driver) + COMPREPLY=($(compgen -W "portio cros-ec windows" -- "${cur}")) + return 0 + ;; + --pd-addrs) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --pd-ports) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --flash-gpu-descriptor-file) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --dump-gpu-descriptor-file) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --generate-completions) + COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + esac } -complete -F _framework_tool framework_tool +if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then + complete -F _framework_tool -o nosort -o bashdefault -o default framework_tool +else + complete -F _framework_tool -o bashdefault -o default framework_tool +fi diff --git a/completions/fish/framework_tool.fish b/completions/fish/framework_tool.fish new file mode 100644 index 00000000..58b65d86 --- /dev/null +++ b/completions/fish/framework_tool.fish @@ -0,0 +1,98 @@ +complete -c framework_tool -l flash-gpu-descriptor -r +complete -c framework_tool -l device -r -f -a "bios\t'' +ec\t'' +pd0\t'' +pd1\t'' +rtm01\t'' +rtm23\t'' +ac-left\t'' +ac-right\t''" +complete -c framework_tool -l compare-version -r +complete -c framework_tool -l fansetduty -d 'Set fan duty cycle (0-100%)' -r +complete -c framework_tool -l fansetrpm -d 'Set fan RPM (limited by EC fan table max RPM)' -r +complete -c framework_tool -l autofanctrl -d 'Turn on automatic fan speed control' -r +complete -c framework_tool -l pd-reset -d 'Reset a specific PD controller (for debugging only)' -r +complete -c framework_tool -l pd-disable -d 'Disable all ports on a specific PD controller (for debugging only)' -r +complete -c framework_tool -l pd-enable -d 'Enable all ports on a specific PD controller (for debugging only)' -r +complete -c framework_tool -l dp-hdmi-update -d 'Update the DisplayPort or HDMI Expansion Card' -r -F +complete -c framework_tool -l pd-bin -d 'Parse versions from PD firmware binary file' -r -F +complete -c framework_tool -l ec-bin -d 'Parse versions from EC firmware binary file' -r -F +complete -c framework_tool -l capsule -d 'Parse UEFI Capsule information from binary file' -r -F +complete -c framework_tool -l dump -d 'Dump extracted UX capsule bitmap image to a file' -r -F +complete -c framework_tool -l h2o-capsule -d 'Parse UEFI Capsule information from binary file' -r -F +complete -c framework_tool -l dump-ec-flash -d 'Dump EC flash contents' -r -F +complete -c framework_tool -l flash-ec -d 'Flash EC (RO+RW) with new firmware from file - may render your hardware unbootable!' -r -F +complete -c framework_tool -l flash-ro-ec -d 'Flash EC with new RO firmware from file - may render your hardware unbootable!' -r -F +complete -c framework_tool -l flash-rw-ec -d 'Flash EC with new RW firmware from file' -r -F +complete -c framework_tool -l inputdeck-mode -d 'Set input deck power mode [possible values: auto, off, on] (Framework 16 only)' -r -f -a "auto\t'' +off\t'' +on\t''" +complete -c framework_tool -l charge-limit -d 'Get or set max charge limit' -r +complete -c framework_tool -l charge-current-limit -d 'Set max charge current limit' -r +complete -c framework_tool -l charge-rate-limit -d 'Set max charge current limit' -r +complete -c framework_tool -l get-gpio -d 'Get GPIO value by name or all, if no name provided' -r +complete -c framework_tool -l fp-led-level -d 'Get or set fingerprint LED brightness level' -r -f -a "high\t'' +medium\t'' +low\t'' +ultra-low\t'' +auto\t''" +complete -c framework_tool -l fp-brightness -d 'Get or set fingerprint LED brightness percentage' -r +complete -c framework_tool -l kblight -d 'Set keyboard backlight percentage or get, if no value provided' -r +complete -c framework_tool -l remap-key -d 'Remap a key by changing the scancode' -r +complete -c framework_tool -l rgbkbd -d 'Set the color of to . Multiple colors for adjacent keys can be set at once. [ ...] Example: 0 0xFF000 0x00FF00 0x0000FF' -r +complete -c framework_tool -l ps2-enable -d 'Control PS2 touchpad emulation (DEBUG COMMAND, if touchpad not working, reboot system)' -r -f -a "true\t'' +false\t''" +complete -c framework_tool -l tablet-mode -d 'Set tablet mode override' -r -f -a "auto\t'' +tablet\t'' +laptop\t''" +complete -c framework_tool -l touchscreen-enable -d 'Enable/disable touchscreen' -r -f -a "true\t'' +false\t''" +complete -c framework_tool -l console -d 'Get EC console, choose whether recent or to follow the output' -r -f -a "recent\t'' +follow\t''" +complete -c framework_tool -l reboot-ec -d 'Control EC RO/RW jump' -r -f -a "reboot\t'' +jump-ro\t'' +jump-rw\t'' +cancel-jump\t'' +disable-jump\t''" +complete -c framework_tool -l ec-hib-delay -d 'Get or set EC hibernate delay (S5 to G3)' -r +complete -c framework_tool -l hash -d 'Hash a file of arbitrary data' -r -F +complete -c framework_tool -l driver -d 'Select which driver is used. By default portio is used' -r -f -a "portio\t'' +cros-ec\t'' +windows\t''" +complete -c framework_tool -l pd-addrs -d 'Specify I2C addresses of the PD chips (Advanced)' -r +complete -c framework_tool -l pd-ports -d 'Specify I2C ports of the PD chips (Advanced)' -r +complete -c framework_tool -l flash-gpu-descriptor-file -d 'File to write to the gpu EEPROM' -r -F +complete -c framework_tool -l dump-gpu-descriptor-file -d 'File to dump the gpu EEPROM to' -r -F +complete -c framework_tool -l generate-completions -d 'Generate shell completions and print to stdout' -r -f -a "bash\t'' +elvish\t'' +fish\t'' +powershell\t'' +zsh\t''" +complete -c framework_tool -s v -l verbose -d 'Increase logging verbosity' +complete -c framework_tool -s q -l quiet -d 'Decrease logging verbosity' +complete -c framework_tool -l versions -d 'List current firmware versions' +complete -c framework_tool -l version -d 'Show tool version information (Add -vv for more details)' +complete -c framework_tool -l features -d 'Show features support by the firmware' +complete -c framework_tool -l esrt -d 'Display the UEFI ESRT table' +complete -c framework_tool -l power -d 'Show current power status of battery and AC (Add -vv for more details)' +complete -c framework_tool -l thermal -d 'Print thermal information (Temperatures and Fan speed)' +complete -c framework_tool -l sensors -d 'Print sensor information (ALS, G-Sensor)' +complete -c framework_tool -l pdports -d 'Show information about USB-C PD ports' +complete -c framework_tool -l info -d 'Show info from SMBIOS (Only on UEFI)' +complete -c framework_tool -l pd-info -d 'Show details about the PD controllers' +complete -c framework_tool -l dp-hdmi-info -d 'Show details about connected DP or HDMI Expansion Cards' +complete -c framework_tool -l audio-card-info -d 'Show details about connected Audio Expansion Cards (Needs root privileges)' +complete -c framework_tool -l privacy -d 'Show privacy switch statuses (camera and microphone)' +complete -c framework_tool -l intrusion -d 'Show status of intrusion switch' +complete -c framework_tool -l inputdeck -d 'Show status of the input modules (Framework 16 only)' +complete -c framework_tool -l expansion-bay -d 'Show status of the expansion bay (Framework 16 only)' +complete -c framework_tool -l stylus-battery -d 'Check stylus battery level (USI 2.0 stylus only)' +complete -c framework_tool -l uptimeinfo +complete -c framework_tool -l s0ix-counter +complete -c framework_tool -s t -l test -d 'Run self-test to check if interaction with EC is possible' +complete -c framework_tool -l test-retimer -d 'Run self-test to check if interaction with retimers is possible' +complete -c framework_tool -l boardid -d 'Print all board IDs' +complete -c framework_tool -s f -l force -d 'Force execution of an unsafe command - may render your hardware unbootable!' +complete -c framework_tool -l dry-run -d 'Simulate execution of a command (e.g. --flash-ec)' +complete -c framework_tool -l nvidia -d 'Show NVIDIA GPU information (Framework 16 only)' +complete -c framework_tool -s h -l help -d 'Print help' diff --git a/completions/zsh/_framework_tool b/completions/zsh/_framework_tool index 2d473c8f..81d44eab 100644 --- a/completions/zsh/_framework_tool +++ b/completions/zsh/_framework_tool @@ -1,55 +1,106 @@ #compdef framework_tool -local -a options +autoload -U is-at-least -options=( - '--flash-gpu-descriptor[]' - '-v[Increase logging verbosity]' - '-q[Decrease logging verbosity]' - '--versions[Show current firmware versions]' - '--version[Show tool version information (Add -vv for more details)]' - '--features[Show features supported by the firmware]' - '--esrt[Display the UEFI ESRT table]' - '--device[Specify device type]:device:(bios ec pd0 pd1 rtm01 rtm23 ac-left ac-right)' - '--compare-version[Specify version to compare]:compare_version' - '--power[Show current power status of battery and AC (Add -vv for more details)]' - '--thermal[Print thermal information (Temperatures and Fan speed)]' - '--sensors[Print sensor information (ALS, G-Sensor)]' - '--pdports[Show information about USB-C PD ports]' - '--info[Show info from SMBIOS (Only on UEFI)]' - '--pd-info[Show details about the PD controllers]' - '--dp-hdmi-info[Show details about connected DP or HDMI Expansion Cards]' - '--dp-hdmi-update[Update the DisplayPort or HDMI Expansion Card]:update_bin' - '--audio-card-info[Show details about connected Audio Expansion Cards (Needs root privileges)]' - '--privacy[Show privacy switch statuses (camera and microphone)]' - '--pd-bin[Parse versions from PD firmware binary file]:pd_bin' - '--ec-bin[Parse versions from EC firmware binary file]:ec_bin' - '--capsule[Parse UEFI Capsule information from binary file]:capsule' - '--dump[Dump extracted UX capsule bitmap image to a file]:dump' - '--ho2-capsule[Parse UEFI Capsule information from binary file]:ho2_capsule' - '--dump-ec-flash[Dump EC flash contents]:dump_ec_flash' - '--flash-ec[Flash EC with new firmware from file]:flash_ec' - '--flash-ro-ec[Flash EC with new RO firmware from file]:flash_ro_ec' - '--flash-rw-ec[Flash EC with new RW firmware from file]:flash_rw_ec' - '--intrusion[Show status of intrusion switch]' - '--inputdeck[Show status of the input deck]' - '--inputdeck-mode[Set input deck power mode]:inputdeck_mode:(auto off on)' - '--charge-limit[Get or set max charge limit]:charge_limit' - '--get-gpio[Get GPIO value by name]:get_gpio' - '--fp-led-level-gpio[Get or set fingerprint LED brightness level]:fp_led_level:(high medium low ultra-low auto)' - '--fp-brightness[Get or set fingerprint LED brightness]:fp_brightness' - '--kblight[Set keyboard backlight percentage or get, if no value provided]:kblight' - '--rgbkbd[Set the color of to .]' - '--tablet-mode[Set tablet mode override]:tablet_mode:(auto tablet laptop)' - '--touchscreen-enable[Enable/disable touchscreen]:touchscreen_enable:(true false)' - '--console[Get EC console, choose whether recent or to follow the output]:console:(recent follow)' - '--reboot-ec[Control EC RO/RW jump]:reboot_ec:(reboot jump-ro jump-rw cancel-jump disable-jump)' - '--hash[Hash a file of arbitrary data]:hash' - '--driver[Select which driver is used]:driver:(portio cros-ec windows)' - '--pd-addrs[Specify I2C addresses of the PD chips (Advanced)]:pd_addrs' - '--pd-ports[Specify I2C ports of the PD chips (Advanced)]:pd_ports' - '-t[Run self-test to check if interaction with EC is possible]' - '-h[Print help]' -) +_framework_tool() { + typeset -A opt_args + typeset -a _arguments_options + local ret=1 -_arguments -s -S $options + if is-at-least 5.2; then + _arguments_options=(-s -S -C) + else + _arguments_options=(-s -C) + fi + + local context curcontext="$curcontext" state line + _arguments "${_arguments_options[@]}" : \ +'--flash-gpu-descriptor=[]: :_default: :_default' \ +'--device=[]:DEVICE:(bios ec pd0 pd1 rtm01 rtm23 ac-left ac-right)' \ +'--compare-version=[]:COMPARE_VERSION:_default' \ +'*--fansetduty=[Set fan duty cycle (0-100%)]::FANSETDUTY:_default' \ +'*--fansetrpm=[Set fan RPM (limited by EC fan table max RPM)]::FANSETRPM:_default' \ +'--autofanctrl=[Turn on automatic fan speed control]::AUTOFANCTRL:_default' \ +'--pd-reset=[Reset a specific PD controller (for debugging only)]:PD_RESET:_default' \ +'--pd-disable=[Disable all ports on a specific PD controller (for debugging only)]:PD_DISABLE:_default' \ +'--pd-enable=[Enable all ports on a specific PD controller (for debugging only)]:PD_ENABLE:_default' \ +'--dp-hdmi-update=[Update the DisplayPort or HDMI Expansion Card]:UPDATE_BIN:_files' \ +'--pd-bin=[Parse versions from PD firmware binary file]:PD_BIN:_files' \ +'--ec-bin=[Parse versions from EC firmware binary file]:EC_BIN:_files' \ +'--capsule=[Parse UEFI Capsule information from binary file]:CAPSULE:_files' \ +'--dump=[Dump extracted UX capsule bitmap image to a file]:DUMP:_files' \ +'--h2o-capsule=[Parse UEFI Capsule information from binary file]:H2O_CAPSULE:_files' \ +'--dump-ec-flash=[Dump EC flash contents]:DUMP_EC_FLASH:_files' \ +'--flash-ec=[Flash EC (RO+RW) with new firmware from file - may render your hardware unbootable!]:FLASH_EC:_files' \ +'--flash-ro-ec=[Flash EC with new RO firmware from file - may render your hardware unbootable!]:FLASH_RO_EC:_files' \ +'--flash-rw-ec=[Flash EC with new RW firmware from file]:FLASH_RW_EC:_files' \ +'--inputdeck-mode=[Set input deck power mode \[possible values\: auto, off, on\] (Framework 16 only)]:INPUTDECK_MODE:(auto off on)' \ +'--charge-limit=[Get or set max charge limit]::CHARGE_LIMIT:_default' \ +'*--charge-current-limit=[Set max charge current limit]:CHARGE_CURRENT_LIMIT:_default' \ +'*--charge-rate-limit=[Set max charge current limit]:CHARGE_RATE_LIMIT:_default' \ +'--get-gpio=[Get GPIO value by name or all, if no name provided]::GET_GPIO:_default' \ +'--fp-led-level=[Get or set fingerprint LED brightness level]::FP_LED_LEVEL:(high medium low ultra-low auto)' \ +'--fp-brightness=[Get or set fingerprint LED brightness percentage]::FP_BRIGHTNESS:_default' \ +'--kblight=[Set keyboard backlight percentage or get, if no value provided]::KBLIGHT:_default' \ +'*--remap-key=[Remap a key by changing the scancode]:REMAP_KEY:_default:REMAP_KEY:_default:REMAP_KEY:_default' \ +'*--rgbkbd=[Set the color of to . Multiple colors for adjacent keys can be set at once. \[ ...\] Example\: 0 0xFF000 0x00FF00 0x0000FF]:START:_default:START:_default' \ +'--ps2-enable=[Control PS2 touchpad emulation (DEBUG COMMAND, if touchpad not working, reboot system)]:PS2_ENABLE:(true false)' \ +'--tablet-mode=[Set tablet mode override]:TABLET_MODE:(auto tablet laptop)' \ +'--touchscreen-enable=[Enable/disable touchscreen]:TOUCHSCREEN_ENABLE:(true false)' \ +'--console=[Get EC console, choose whether recent or to follow the output]:CONSOLE:(recent follow)' \ +'--reboot-ec=[Control EC RO/RW jump]:REBOOT_EC:(reboot jump-ro jump-rw cancel-jump disable-jump)' \ +'--ec-hib-delay=[Get or set EC hibernate delay (S5 to G3)]::EC_HIB_DELAY:_default' \ +'--hash=[Hash a file of arbitrary data]:HASH:_files' \ +'--driver=[Select which driver is used. By default portio is used]:DRIVER:(portio cros-ec windows)' \ +'*--pd-addrs=[Specify I2C addresses of the PD chips (Advanced)]:PD_ADDRS:_default:PD_ADDRS:_default:PD_ADDRS:_default' \ +'*--pd-ports=[Specify I2C ports of the PD chips (Advanced)]:PD_PORTS:_default:PD_PORTS:_default:PD_PORTS:_default' \ +'--flash-gpu-descriptor-file=[File to write to the gpu EEPROM]:FLASH_GPU_DESCRIPTOR_FILE:_files' \ +'--dump-gpu-descriptor-file=[File to dump the gpu EEPROM to]:DUMP_GPU_DESCRIPTOR_FILE:_files' \ +'--generate-completions=[Generate shell completions and print to stdout]:SHELL:(bash elvish fish powershell zsh)' \ +'*-v[Increase logging verbosity]' \ +'*--verbose[Increase logging verbosity]' \ +'(-v --verbose)*-q[Decrease logging verbosity]' \ +'(-v --verbose)*--quiet[Decrease logging verbosity]' \ +'--versions[List current firmware versions]' \ +'--version[Show tool version information (Add -vv for more details)]' \ +'--features[Show features support by the firmware]' \ +'--esrt[Display the UEFI ESRT table]' \ +'--power[Show current power status of battery and AC (Add -vv for more details)]' \ +'--thermal[Print thermal information (Temperatures and Fan speed)]' \ +'--sensors[Print sensor information (ALS, G-Sensor)]' \ +'--pdports[Show information about USB-C PD ports]' \ +'--info[Show info from SMBIOS (Only on UEFI)]' \ +'--pd-info[Show details about the PD controllers]' \ +'--dp-hdmi-info[Show details about connected DP or HDMI Expansion Cards]' \ +'--audio-card-info[Show details about connected Audio Expansion Cards (Needs root privileges)]' \ +'--privacy[Show privacy switch statuses (camera and microphone)]' \ +'--intrusion[Show status of intrusion switch]' \ +'--inputdeck[Show status of the input modules (Framework 16 only)]' \ +'--expansion-bay[Show status of the expansion bay (Framework 16 only)]' \ +'--stylus-battery[Check stylus battery level (USI 2.0 stylus only)]' \ +'--uptimeinfo[]' \ +'--s0ix-counter[]' \ +'-t[Run self-test to check if interaction with EC is possible]' \ +'--test[Run self-test to check if interaction with EC is possible]' \ +'--test-retimer[Run self-test to check if interaction with retimers is possible]' \ +'--boardid[Print all board IDs]' \ +'-f[Force execution of an unsafe command - may render your hardware unbootable!]' \ +'--force[Force execution of an unsafe command - may render your hardware unbootable!]' \ +'--dry-run[Simulate execution of a command (e.g. --flash-ec)]' \ +'--nvidia[Show NVIDIA GPU information (Framework 16 only)]' \ +'-h[Print help]' \ +'--help[Print help]' \ +&& ret=0 +} + +(( $+functions[_framework_tool_commands] )) || +_framework_tool_commands() { + local commands; commands=() + _describe -t commands 'framework_tool commands' commands "$@" +} + +if [ "$funcstack[1]" = "_framework_tool" ]; then + _framework_tool "$@" +else + compdef _framework_tool framework_tool +fi From 447f2eabcc77cee5a07c74aa8e630914c5e9a664 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 26 Jan 2026 13:16:11 +0800 Subject: [PATCH 3/3] gh-actions: Make sure shell completions are updated Or error in CI if not. Signed-off-by: Daniel Schaefer --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a46fc070..cc6a0f8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -179,6 +179,16 @@ jobs: - name: Run cargo clippy run: cargo clippy -p framework_lib -p framework_tool -- -D warnings + - name: Check shell completions are up to date + run: | + cargo build -p framework_tool + ./target/debug/framework_tool --generate-completions bash > /tmp/bash_completions + ./target/debug/framework_tool --generate-completions zsh > /tmp/zsh_completions + ./target/debug/framework_tool --generate-completions fish > /tmp/fish_completions + diff completions/bash/framework_tool /tmp/bash_completions || { echo "Shell completions are out of date. See completions/README.md for regeneration instructions."; exit 1; } + diff completions/zsh/_framework_tool /tmp/zsh_completions || { echo "Shell completions are out of date. See completions/README.md for regeneration instructions."; exit 1; } + diff completions/fish/framework_tool.fish /tmp/fish_completions || { echo "Shell completions are out of date. See completions/README.md for regeneration instructions."; exit 1; } + # Just make sure doc generation works doc: name: Generate docs