From 35fd34677d891378fe56bf58a7709481d29b0344 Mon Sep 17 00:00:00 2001 From: Rafael Passos Date: Tue, 7 Jul 2026 19:04:46 -0300 Subject: [PATCH 1/3] Remove xtask completion generation Signed-off-by: Rafael Passos --- .cargo/config.toml | 2 -- Cargo.lock | 9 --------- Cargo.toml | 2 +- xtask/Cargo.toml | 9 --------- xtask/src/main.rs | 35 ----------------------------------- 5 files changed, 1 insertion(+), 56 deletions(-) delete mode 100644 .cargo/config.toml delete mode 100644 xtask/Cargo.toml delete mode 100644 xtask/src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 35049cb..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[alias] -xtask = "run --package xtask --" diff --git a/Cargo.lock b/Cargo.lock index 78b3ef0..00e61b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2346,15 +2346,6 @@ dependencies = [ "wasmparser", ] -[[package]] -name = "xtask" -version = "0.1.0" -dependencies = [ - "clap", - "clap_complete", - "siomon", -] - [[package]] name = "zerocopy" version = "0.8.48" diff --git a/Cargo.toml b/Cargo.toml index cf7fe3b..393f154 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ csv = ["dep:csv"] raw-cpuid = "11" [workspace] -members = [".", "xtask"] +members = ["."] [workspace.dependencies] clap = { version = "4", features = ["derive", "env", "string"] } diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml deleted file mode 100644 index 923b9e7..0000000 --- a/xtask/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "xtask" -version = "0.1.0" -edition = "2024" - -[dependencies] -siomon = { path = ".." } -clap.workspace = true -clap_complete.workspace = true diff --git a/xtask/src/main.rs b/xtask/src/main.rs deleted file mode 100644 index 71beb63..0000000 --- a/xtask/src/main.rs +++ /dev/null @@ -1,35 +0,0 @@ -use clap::{Parser, Subcommand}; - -#[derive(Parser)] -struct Cli { - #[command(subcommand)] - pub(crate) command: Cmd, -} -#[derive(Subcommand)] -enum Cmd { - ShellCompletion(ShellCompletion), -} - -#[derive(Parser)] -struct ShellCompletion { - #[clap(value_enum)] - shell: clap_complete::Shell, -} - -fn main() { - let cli = Cli::parse(); - - let mut cmd = ::command(); - match cli.command { - Cmd::ShellCompletion(shell_completion) => { - let bin_name = cmd.get_name().to_string(); - - clap_complete::generate( - shell_completion.shell, - &mut cmd, - bin_name, - &mut std::io::stdout(), - ); - } - } -} From 47a5ea8610e3d1ed02df2334638dc5c605b53f13 Mon Sep 17 00:00:00 2001 From: Rafael Passos Date: Tue, 7 Jul 2026 19:06:58 -0300 Subject: [PATCH 2/3] Create a build script to generate shell completion Signed-off-by: Rafael Passos --- Cargo.lock | 5 +-- Cargo.toml | 5 +++ build.rs | 17 ++++++++++ src/cli.rs | 93 +---------------------------------------------------- src/lib.rs | 2 ++ src/opts.rs | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 94 deletions(-) create mode 100644 build.rs create mode 100644 src/opts.rs diff --git a/Cargo.lock b/Cargo.lock index 00e61b9..1204247 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -259,9 +259,9 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.6.0" +version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19c9f1dde76b736e3681f28cec9d5a61299cbaae0fce80a68e43724ad56031eb" +checksum = "db8b397918185f0161ff3d6fcaa9e4bfc09b8367caf6e1d4a2848e5477ed027b" dependencies = [ "clap", ] @@ -1635,6 +1635,7 @@ version = "0.2.3" dependencies = [ "chrono", "clap", + "clap_complete", "crossterm", "csv", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 393f154..8719a29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ license = "MIT" keywords = ["hardware", "sensors", "hwmon", "system-info", "monitoring"] categories = ["command-line-utilities", "hardware-support"] repository = "https://github.com/level1techs/siomon" +build = "build.rs" exclude = ["packaging/", "assets/", "kmod/", ".github/", "CONTRIBUTING.md", "PACKAGING.md", "cliff.toml"] [[bin]] @@ -34,6 +35,10 @@ members = ["."] clap = { version = "4", features = ["derive", "env", "string"] } clap_complete = "4" +[build-dependencies] +clap.workspace = true +clap_complete.workspace = true + [dependencies] # Serialization diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..33377ee --- /dev/null +++ b/build.rs @@ -0,0 +1,17 @@ +use clap::CommandFactory; +use clap_complete::aot::{Shell, generate_to}; + +include!("src/opts.rs"); + +fn main() -> std::io::Result<()> { + let outdir = std::env::var("CARGO_TARGET_DIR").unwrap_or("./target".to_string()); + let mut cmd = Cli::command(); + + std::fs::create_dir_all(&outdir)?; + generate_to(Shell::Bash, &mut cmd, "sio", &outdir)?; + generate_to(Shell::Zsh, &mut cmd, "sio", &outdir)?; + generate_to(Shell::Fish, &mut cmd, "sio", &outdir)?; + + println!("cargo:warning=shell completions generated in {outdir}/"); + Ok(()) +} diff --git a/src/cli.rs b/src/cli.rs index 4afcf18..a68bb9e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,99 +1,8 @@ //! Command-line argument parsing and config-file application. -use clap::{Parser, Subcommand, ValueEnum}; - use crate::config::SiomonConfig; -#[derive(Parser, Debug)] -#[command( - name = "sio", - about = "Linux hardware information and sensor monitoring", - version, - author -)] -pub struct Cli { - #[command(subcommand)] - pub command: Option, - - /// Output format - #[arg(short = 'f', long, value_enum, default_value_t = OutputFormat::Text, global = true)] - pub format: OutputFormat, - - /// Run in TUI (interactive) sensor monitor mode (press '/' to cross-filter) - #[arg(short = 'm', long = "monitor", global = true)] - pub tui: bool, - - /// Sensor polling interval in milliseconds - #[arg(long, default_value_t = 1000, global = true)] - pub interval: u64, - - /// Disable NVIDIA GPU detection - #[arg(long, global = true)] - pub no_nvidia: bool, - - /// Enable direct I/O port and I2C sensor reading (requires root) - #[arg(long, global = true)] - pub direct_io: bool, - - /// Show empty/unavailable fields - #[arg(long, global = true)] - pub show_empty: bool, - - /// Log sensor data to CSV file while monitoring - #[arg(long, global = true)] - pub log: Option, - - /// Sensor alert rules (e.g., "hwmon/nct6798/temp1 > 80 @30s") - #[arg(long = "alert", value_name = "RULE", global = true)] - pub alerts: Vec, - - /// Color mode - #[arg(long, value_enum, default_value_t = ColorMode::Auto, global = true)] - pub color: ColorMode, -} - -#[derive(Subcommand, Debug)] -pub enum Commands { - /// CPU information - Cpu, - /// GPU information - Gpu, - /// Memory information - Memory, - /// Storage device information - Storage, - /// Network adapter information - Network, - /// PCI device list - Pci, - /// USB device list - Usb, - /// Audio device information - Audio, - /// Battery information - Battery, - /// Motherboard and BIOS information - Board, - /// PCIe link details (speed, width, ASPM) - Pcie, - /// Sensor readings (one-shot snapshot) - Sensors, -} - -#[derive(ValueEnum, Clone, Debug, PartialEq, Eq)] -pub enum OutputFormat { - Text, - Json, - Xml, - Html, -} - -#[derive(ValueEnum, Clone, Debug)] -pub enum ColorMode { - Auto, - Always, - Never, -} +pub use crate::opts::*; impl Cli { /// Apply config file values for any CLI argument that wasn't explicitly set. diff --git a/src/lib.rs b/src/lib.rs index 3ed2a4a..00d6f91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ /// Command-line argument parsing and config application (clap). pub mod cli; +/// Clap argument definitions (shared with build.rs via include!). +mod opts; /// One-shot hardware information collectors (`Collector` trait). pub mod collectors; /// Configuration file loading (`~/.config/siomon/config.toml`). diff --git a/src/opts.rs b/src/opts.rs new file mode 100644 index 0000000..d58b304 --- /dev/null +++ b/src/opts.rs @@ -0,0 +1,92 @@ +use clap::{Parser, Subcommand, ValueEnum}; + +#[derive(Parser, Debug)] +#[command( + name = "sio", + about = "Linux hardware information and sensor monitoring", + version, + author +)] +pub struct Cli { + #[command(subcommand)] + pub command: Option, + + /// Output format + #[arg(short = 'f', long, value_enum, default_value_t = OutputFormat::Text, global = true)] + pub format: OutputFormat, + + /// Run in TUI (interactive) sensor monitor mode (press '/' to cross-filter) + #[arg(short = 'm', long = "monitor", global = true)] + pub tui: bool, + + /// Sensor polling interval in milliseconds + #[arg(long, default_value_t = 1000, global = true)] + pub interval: u64, + + /// Disable NVIDIA GPU detection + #[arg(long, global = true)] + pub no_nvidia: bool, + + /// Enable direct I/O port and I2C sensor reading (requires root) + #[arg(long, global = true)] + pub direct_io: bool, + + /// Show empty/unavailable fields + #[arg(long, global = true)] + pub show_empty: bool, + + /// Log sensor data to CSV file while monitoring + #[arg(long, global = true)] + pub log: Option, + + /// Sensor alert rules (e.g., "hwmon/nct6798/temp1 > 80 @30s") + #[arg(long = "alert", value_name = "RULE", global = true)] + pub alerts: Vec, + + /// Color mode + #[arg(long, value_enum, default_value_t = ColorMode::Auto, global = true)] + pub color: ColorMode, +} + +#[derive(Subcommand, Debug)] +pub enum Commands { + /// CPU information + Cpu, + /// GPU information + Gpu, + /// Memory information + Memory, + /// Storage device information + Storage, + /// Network adapter information + Network, + /// PCI device list + Pci, + /// USB device list + Usb, + /// Audio device information + Audio, + /// Battery information + Battery, + /// Motherboard and BIOS information + Board, + /// PCIe link details (speed, width, ASPM) + Pcie, + /// Sensor readings (one-shot snapshot) + Sensors, +} + +#[derive(ValueEnum, Clone, Debug, PartialEq, Eq)] +pub enum OutputFormat { + Text, + Json, + Xml, + Html, +} + +#[derive(ValueEnum, Clone, Debug)] +pub enum ColorMode { + Auto, + Always, + Never, +} From 69e5933658f09f4b36ec7b347f5f8480e45f32d6 Mon Sep 17 00:00:00 2001 From: Rafael Passos Date: Tue, 7 Jul 2026 19:07:26 -0300 Subject: [PATCH 3/3] Update packaging to use the completion generated in normal build Signed-off-by: Rafael Passos --- packaging/aur/PKGBUILD | 14 ++++---------- packaging/launchpad/debian/rules | 6 +----- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/packaging/aur/PKGBUILD b/packaging/aur/PKGBUILD index 3ab2433..e293a47 100644 --- a/packaging/aur/PKGBUILD +++ b/packaging/aur/PKGBUILD @@ -57,16 +57,10 @@ package() { export RUSTUP_TOOLCHAIN=stable cargo install --no-track --frozen --all-features --root "$pkgdir/usr/" --path . - # Shell completions — xtask reuses the build cache from cargo install above - install -dm755 "$pkgdir/usr/share/bash-completion/completions" - install -dm755 "$pkgdir/usr/share/zsh/site-functions" - install -dm755 "$pkgdir/usr/share/fish/vendor_completions.d" - cargo run --frozen --package xtask -- shell-completion bash \ - > "$pkgdir/usr/share/bash-completion/completions/sio" - cargo run --frozen --package xtask -- shell-completion zsh \ - > "$pkgdir/usr/share/zsh/site-functions/_sio" - cargo run --frozen --package xtask -- shell-completion fish \ - > "$pkgdir/usr/share/fish/vendor_completions.d/sio.fish" + # Shell completions (pre-generated by build.rs) + install -Dm644 target/sio.bash "$pkgdir/usr/share/bash-completion/completions/sio" + install -Dm644 target/_sio "$pkgdir/usr/share/zsh/site-functions/_sio" + install -Dm644 target/sio.fish "$pkgdir/usr/share/fish/vendor_completions.d/sio.fish" install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" diff --git a/packaging/launchpad/debian/rules b/packaging/launchpad/debian/rules index ad2f2e7..ede5178 100644 --- a/packaging/launchpad/debian/rules +++ b/packaging/launchpad/debian/rules @@ -11,17 +11,13 @@ override_dh_auto_configure: override_dh_auto_build: cargo build --frozen --release --all-features - cargo run --frozen --package xtask -- shell-completion bash > target/sio.bash - cargo run --frozen --package xtask -- shell-completion zsh > target/sio.zsh - cargo run --frozen --package xtask -- shell-completion fish > target/sio.fish # Tests require hardware/sysfs interfaces not available in Launchpad build chroot override_dh_auto_test: override_dh_auto_install: - install -D -m 0755 target/release/sio debian/siomon/usr/bin/sio install -D -m 0644 target/sio.bash debian/siomon/usr/share/bash-completion/completions/sio - install -D -m 0644 target/sio.zsh debian/siomon/usr/share/zsh/vendor-completions/_sio + install -D -m 0644 target/_sio debian/siomon/usr/share/zsh/vendor-completions/_sio install -D -m 0644 target/sio.fish debian/siomon/usr/share/fish/vendor_completions.d/sio.fish override_dh_auto_clean: