From 2ab7df378d8cb40775ac0ecd2849fa9966386a2e Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Mon, 20 Mar 2023 16:57:44 +0200 Subject: Use clap to parse paths --- src/main.rs | 6 ++---- src/parser.rs | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e02be3e..56cd729 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,8 +62,7 @@ fn run_command(user_input: String) -> Result, ShackleError> command.arg("advertise-refs"); } - // TODO: This should definitely be part of the arg parsing! - command.arg(&upload_pack_args.directory.trim_matches('\'')); + command.arg(&upload_pack_args.directory); command.spawn()?.wait()?; } @@ -74,8 +73,7 @@ fn run_command(user_input: String) -> Result, ShackleError> command.arg("--http-backend-info-refs"); } - // TODO: This should definitely be part of the arg parsing! - command.arg(&receive_pack_args.directory.trim_matches('\'')); + command.arg(&receive_pack_args.directory); command.spawn()?.wait()?; } diff --git a/src/parser.rs b/src/parser.rs index 9938924..6a6459b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,5 +1,5 @@ use clap::{Parser, Subcommand}; -use std::str::FromStr; +use std::{path::PathBuf, str::FromStr}; use thiserror::Error; #[derive(Parser, Clone, Debug, PartialEq, Eq)] @@ -35,14 +35,14 @@ pub struct GitUploadPackArgs { pub stateless_rpc: bool, #[arg(long)] pub advertise_refs: bool, - pub directory: String, + pub directory: PathBuf, } #[derive(Parser, Clone, Debug, PartialEq, Eq)] pub struct GitReceivePackArgs { #[arg(long)] pub http_backend_info_refs: bool, - pub directory: String, + pub directory: PathBuf, } #[derive(Error, Debug)] @@ -98,7 +98,7 @@ mod test { timeout: None, stateless_rpc: true, advertise_refs: false, - directory: "foobar.git".to_owned(), + directory: PathBuf::from("foobar.git"), }) ); } -- cgit v1.2.3