From 9cf87bdd0175ba98640b982e8421fc933ecc94d2 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Mon, 3 Jun 2024 11:53:26 -0400 Subject: [PATCH] feat: cli argument parsing --- src/main.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..682ccf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,46 @@ -fn main() { - println!("Hello, world!"); +use std::ffi::c_int; +use std::process; +use std::convert::From; +use std::path::PathBuf; +use signal_hook::consts::signal::*; + +use clap::{Parser, ValueEnum}; +use anyhow; + +#[derive(Parser, Clone, ValueEnum)] +pub enum HandledSignals { + SIGHUP, + SIGUSR1, + SIGUSR2, +} + +impl From for c_int { + fn from(value: HandledSignals) -> Self { + match value { + HandledSignals::SIGHUP => SIGHUP, + HandledSignals::SIGUSR1 => SIGUSR1, + HandledSignals::SIGUSR2 => SIGUSR2, + } + } +} + +#[derive(Parser)] +#[command(version, about, long_about = None)] +struct Args { + #[arg(short = 'e', long = "err-path", help="Path to write stderr to")] + std_err_path: PathBuf, + #[arg(short = 'o', long = "out-path", help="Path to write stdout to")] + std_out_path: PathBuf, + #[arg(long = "sig", value_enum, help="Optional signal notifiying that the file paths have been rotated")] + rotated_signal: Option, + #[arg(long="size", help="Optional size at which to rotate the files")] + rotate_size_bytes: Option, + #[arg(last = true, help="Command to run")] + cmd: Vec, +} + +fn main() -> anyhow::Result<()> { + let args = Args::parse(); + println!("Hello, world!"); + return Ok(()); }