From 06834eea8b7ae7b98c81342becbe56717351ab57 Mon Sep 17 00:00:00 2001 From: Christian Meusel Date: Tue, 30 Sep 2025 22:50:12 +0200 Subject: [PATCH 1/2] Derive Debug for Cli Because it should. --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 11c6499..b4a20a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use gpio_utils::config::{self, GpioConfig}; use gpio_utils::options::*; use std::process; -#[derive(Parser)] +#[derive(Debug, Parser)] #[command( name = "GPIO Utils", version, @@ -26,7 +26,7 @@ struct Cli { command: Commands, } -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] enum Commands { /// Read the value of a GPIO Input Read { From 1b1df13ec17b63697e70911b5bb3bdcb082d9e6c Mon Sep 17 00:00:00 2001 From: Christian Meusel Date: Tue, 30 Sep 2025 22:53:21 +0200 Subject: [PATCH 2/2] Allow specifying two common options via env Configuration files an symlink root are used in many subcommands and are expected to be fixed for a certain environment. Allow to conveniently pass them via environment variables. The symlink root has a somewhat special role as it might as well be specified via configuration files and we can't have a default value from the CLI in this case. --- Cargo.toml | 2 +- src/main.rs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b20a1f7..9cb80a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ Rust applications or any other applications. """ [dependencies] -clap = { version = "4.5.48", features = ["derive"] } +clap = { version = "4.5.48", features = ["derive", "env"] } sysfs_gpio = "0.6.2" toml = { version = "<=0.9.6", default-features = false, features = ["parse", "serde"] } glob = "0.3.3" diff --git a/src/main.rs b/src/main.rs index b4a20a7..14dce07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,9 @@ use gpio_utils::config::{self, GpioConfig}; use gpio_utils::options::*; use std::process; +pub const CONFIG_ENV_VAR: &str = "GPIO_UTILS_CONFIG"; +pub const SYMLINK_ROOT_ENV_VAR: &str = "GPIO_UTILS_SYMLINK_ROOT"; + #[derive(Debug, Parser)] #[command( name = "GPIO Utils", @@ -19,8 +22,8 @@ use std::process; about = "Read, Write, and Configure GPIOs" )] struct Cli { - /// additional configuration to use - #[arg(short, long = "config", value_name = "FILE")] + /// additional configuration to use (separator ':') + #[arg(short, long = "config", value_name = "FILE", num_args = 0.., env = CONFIG_ENV_VAR, value_delimiter = ':')] configs: Vec, #[command(subcommand)] command: Commands, @@ -56,13 +59,13 @@ enum Commands { /// The pin name (or number) pin: String, /// root directory for export symlinks - #[arg(short = 'r', long)] + #[arg(short = 'r', long, env = SYMLINK_ROOT_ENV_VAR)] symlink_root: Option, }, /// Export all configured GPIOs ExportAll { /// Export all configured GPIOs - #[arg(short = 'r', long)] + #[arg(short = 'r', long, env = SYMLINK_ROOT_ENV_VAR)] symlink_root: Option, }, /// Export all configured GPIOs @@ -70,13 +73,13 @@ enum Commands { /// The pin name (or number) pin: String, /// root directory for export symlinks - #[arg(short = 'r', long)] + #[arg(short = 'r', long, env = SYMLINK_ROOT_ENV_VAR)] symlink_root: Option, }, /// Unexport all configured, exported GPIOs UnexportAll { /// root directory for export symlinks - #[arg(short = 'r', long)] + #[arg(short = 'r', long, env = SYMLINK_ROOT_ENV_VAR)] symlink_root: Option, }, /// Output status of a GPIO or all GPIOs if no pin is specified