Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 11 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ use gpio_utils::config::{self, GpioConfig};
use gpio_utils::options::*;
use std::process;

#[derive(Parser)]
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",
version,
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<String>,
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
#[derive(Debug, Subcommand)]
enum Commands {
/// Read the value of a GPIO Input
Read {
Expand Down Expand Up @@ -56,27 +59,27 @@ 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<String>,
},
/// 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<String>,
},
/// Export all configured GPIOs
Unexport {
/// 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<String>,
},
/// 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<String>,
},
/// Output status of a GPIO or all GPIOs if no pin is specified
Expand Down