From d952d96a6cb91c5d3e3f5162699f957606e78e1d Mon Sep 17 00:00:00 2001 From: Kieran Klukas Date: Wed, 25 Feb 2026 19:56:39 -0500 Subject: [PATCH] feat: add shell completions --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/main.rs | 12 +++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index fa299c6..fbeb349 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,6 +107,15 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.5.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c757a3b7e39161a4e56f9365141ada2a6c915a8622c408ab6bb4b5d047371031" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.5.55" @@ -176,6 +185,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", + "clap_complete", "crc32fast", "hmac", "libc", diff --git a/Cargo.toml b/Cargo.toml index 58dcc03..99d59fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,4 @@ hmac = "0.12" sha2 = "0.10" serde = { version = "1", features = ["derive"] } serde_json = "1" +clap_complete = "4" diff --git a/src/main.rs b/src/main.rs index a64e627..0e877ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,8 @@ use std::path::PathBuf; use anyhow::{Context, Result, bail}; use clap::builder::styling::{AnsiColor, Effects, Styles}; -use clap::{Parser, Subcommand}; +use clap::{CommandFactory, Parser, Subcommand}; +use clap_complete::Shell; use protocol::{HSMIntf, Opcode}; const STYLES: Styles = Styles::styled() @@ -62,6 +63,11 @@ enum TopLevel { #[command(subcommand)] command: HwCmd, }, + /// Generate shell completions + Completions { + /// Shell to generate completions for + shell: Shell, + }, } // ─── Tools subcommands ─── @@ -271,6 +277,10 @@ fn run(cli: Cli) -> Result<()> { match cli.command { TopLevel::Tools { port, command } => run_tools(&port, command), TopLevel::Hw { port, command } => run_hw(&port, command), + TopLevel::Completions { shell } => { + clap_complete::generate(shell, &mut Cli::command(), "ectf-tools", &mut std::io::stdout()); + Ok(()) + } } }