From b9db974c1749c2f4e3f62b84c977f851f9d9eb59 Mon Sep 17 00:00:00 2001 From: alice pellerin Date: Wed, 29 Apr 2026 21:58:23 -0500 Subject: [PATCH] generate completions --- Cargo.lock | 10 ++++++++++ Cargo.toml | 5 +++++ build.rs | 23 +++++++++++++++++++++++ src/main.rs | 5 ++--- 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 build.rs diff --git a/Cargo.lock b/Cargo.lock index eac7cc4..fca3eba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,6 +188,15 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "660c0520455b1013b9bcb0393d5f643d7e4454fb69c915b8d6d2aa0e9a45acc3" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.6.0" @@ -542,6 +551,7 @@ name = "hexapoda" version = "0.1.0" dependencies = [ "clap", + "clap_complete", "crossterm", "itertools", "ratatui", diff --git a/Cargo.toml b/Cargo.toml index 8c4495f..b21c5f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ keywords = ["cli", "tui", "hex", "tool", "editor"] categories = ["command-line-utilities"] license = "GPL-3.0-only" edition = "2024" +build = "build.rs" [dependencies] clap = { version = "4.6.0", features = ["derive"] } @@ -15,3 +16,7 @@ itertools = "0.14.0" ratatui = "0.30.0" serde = { version = "1.0.228", features = ["derive"] } toml = "1.1.2" + +[build-dependencies] +clap = { version = "4.6.0", features = ["derive"] } +clap_complete = "4.6.3" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..82334c5 --- /dev/null +++ b/build.rs @@ -0,0 +1,23 @@ +use clap::{CommandFactory, ValueEnum}; +use clap_complete::{generate_to, Shell}; +use std::env; +use std::io::Error; + +include!("src/arguments.rs"); + +fn main() -> Result<(), Error> { + let output_folder = match env::var_os("OUT_DIR") { + None => return Ok(()), + Some(output_folder) => output_folder, + }; + + let mut command = Arguments::command(); + for &shell in Shell::value_variants() { + generate_to(shell, &mut command, "hexapoda", &output_folder)?; + } + + println!("cargo:warning=completions generated in {output_folder:?}"); + println!("cargo:rerun-if-changed=src/arguments.rs"); + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 43fefc9..9f1cf5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,6 @@ mod action; mod edit_action; mod arguments; mod window_size; - mod utilities; const BYTES_PER_LINE: usize = 0x10; @@ -34,13 +33,13 @@ const LINES_OF_PADDING: usize = 5; const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; // TODO: +// - update showcase // - `go` goto entered offset // - search // - `/` hex, `A-/` ascii // - if non-hex-digit typed, search ascii -// - update showcase // - inspector translations for varint -// - M mark at selected offset (like Jm) +// - M mark at selected offset? (like Jm) // - diffing // - doesn't have to be anything fancy, just compare each byte 1:1 // - sync scroll ? sync selections ??