From 9830abc2dcde3ca33c0297bdf77dff5b1dc2a823 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Wed, 20 Aug 2025 14:19:36 +0200 Subject: [PATCH] Add CLI parsing Signed-off-by: Lee Smet --- Cargo.toml | 2 +- src/main.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a794d4a..d18da53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] -clap = { version = "4.5.45", features = ["derive"] } +clap = { version = "4.5.45", features = ["derive", "env"] } serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0.143" tokio = { version = "1.47.1", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index e7a11a9..2f6ad84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,47 @@ -fn main() { - println!("Hello, world!"); +use clap::Parser; +use std::net::{IpAddr, SocketAddr}; + +#[derive(Debug, Clone, Parser)] +#[command( + name = "herocoordinator", + version, + about = "Hero Coordinator CLI", + long_about = None +)] +struct Cli { + #[arg( + long = "mycelium-ip", + short = 'i', + env = "MYCELIUM_IP", + default_value = "127.0.0.1", + help = "IP address where Mycelium JSON-RPC is listening (default: 127.0.0.1)" + )] + mycelium_ip: IpAddr, + + #[arg( + long = "mycelium-port", + short = 'p', + env = "MYCELIUM_PORT", + default_value_t = 9651u16, + help = "Port for Mycelium JSON-RPC (default: 9651)" + )] + mycelium_port: u16, + + #[arg( + long = "redis-addr", + short = 'r', + env = "REDIS_ADDR", + default_value = "127.0.0.1:6379", + help = "Socket address of Redis instance (default: 127.0.0.1:6379)" + )] + redis_addr: SocketAddr, +} + +fn main() { + let cli = Cli::parse(); + + println!( + "mycelium_ip={}, mycelium_port={}, redis_addr={}", + cli.mycelium_ip, cli.mycelium_port, cli.redis_addr + ); }