diff --git a/src/main.rs b/src/main.rs index e8d84f4..acb8903 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use clap::Parser; use eyre::Result; -use std::{path::PathBuf, str::FromStr}; +use std::path::PathBuf; /// A command runner that optionally logs the I/O streams to files. #[derive(Debug, Parser, PartialEq)] @@ -8,18 +8,18 @@ use std::{path::PathBuf, str::FromStr}; struct Cli { /// The file to log stdin to. #[clap(short, long, env)] - in_file: Option, + in_file: Option, /// The file to log stdout to. #[clap(short, long, env)] - out_file: Option, + out_file: Option, /// The file to log stderr to. #[clap(short, long, env)] - err_file: Option, + err_file: Option, /// The command to run and its arguments. A command must be specified, arguments are space delimited. - #[clap(last = true)] + #[clap(last = true, required = true, num_args = 1..)] exec: Vec, } @@ -27,35 +27,12 @@ fn main() -> Result<()> { let cli = Cli::parse(); let exec = cli.exec.iter().map(String::as_str).collect::>(); - if exec.is_empty() { - use clap::CommandFactory; - eprintln!("EXEC must have at least one argument."); - eprintln!("{}", Cli::command().render_long_help()); - std::process::exit(1); - } - - let in_file = cli - .in_file - .as_ref() - .map(|s| PathBuf::from_str(s)) - .transpose()?; - let out_file = cli - .out_file - .as_ref() - .map(|s| PathBuf::from_str(s)) - .transpose()?; - let err_file = cli - .err_file - .as_ref() - .map(|s| PathBuf::from_str(s)) - .transpose()?; - let code = runner::run( exec[0], &exec[1..], - in_file.as_deref(), - out_file.as_deref(), - err_file.as_deref(), + cli.in_file.as_deref(), + cli.out_file.as_deref(), + cli.err_file.as_deref(), )?; std::process::exit(code);