From cfdff01fe49f2de1880f4922a98b4a03f01a6e61 Mon Sep 17 00:00:00 2001 From: aawsome <37850842+aawsome@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:12:20 +0200 Subject: [PATCH] fix: parse commands given by arg or env using shell_words (#240) closes https://github.com/rustic-rs/rustic/issues/1177 --- crates/core/Cargo.toml | 3 ++- crates/core/src/repository.rs | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index b795f1f0..5d71c5e8 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -38,7 +38,7 @@ edition = "2021" default = [] cli = ["merge", "clap"] merge = ["dep:merge"] -clap = ["dep:clap"] +clap = ["dep:clap", "dep:shell-words"] webdav = ["dep:dav-server", "dep:futures"] [package.metadata.docs.rs] @@ -94,6 +94,7 @@ dirs = "5.0.1" # cli support clap = { version = "4.5.15", optional = true, features = ["derive", "env", "wrap_help"] } merge = { version = "0.1.0", optional = true } +shell-words = { version = "1.1.0", optional = true } # vfs support dav-server = { version = "0.7.0", default-features = false, optional = true } diff --git a/crates/core/src/repository.rs b/crates/core/src/repository.rs index de8f1f16..56f2ef57 100644 --- a/crates/core/src/repository.rs +++ b/crates/core/src/repository.rs @@ -1,3 +1,6 @@ +// Note: we need a fully qualified Vec here for clap, see https://github.com/clap-rs/clap/issues/4481 +#![allow(unused_qualifications)] + mod warm_up; use std::{ @@ -109,10 +112,13 @@ pub struct RepositoryOptions { global = true, env = "RUSTIC_PASSWORD_COMMAND", conflicts_with_all = &["password", "password_file"], + value_parser = clap::builder::ValueParser::new(shell_words::split), + default_value = "", ))] #[cfg_attr(feature = "merge", merge(strategy = merge::vec::overwrite_empty))] #[serde_as(as = "OneOrMany<_>")] - pub password_command: Vec, + // Note: we need a fully qualified Vec here for clap, see https://github.com/clap-rs/clap/issues/4481 + pub password_command: std::vec::Vec, /// Don't use a cache. #[cfg_attr(feature = "clap", clap(long, global = true, env = "RUSTIC_NO_CACHE"))] @@ -137,13 +143,18 @@ pub struct RepositoryOptions { pub warm_up: bool, /// Warm up needed data pack files by running the command with %id replaced by pack id - #[cfg_attr( - feature = "clap", - clap(long, global = true, conflicts_with = "warm_up") - )] + #[cfg_attr(feature = "clap", clap( + long, + global = true, + conflicts_with = "warm_up", + value_parser = clap::builder::ValueParser::new(shell_words::split), + action = clap::ArgAction::Set, + default_value = "", + ))] #[cfg_attr(feature = "merge", merge(strategy = merge::vec::overwrite_empty))] #[serde_as(as = "OneOrMany<_>")] - pub warm_up_command: Vec, + // Note: we need a fully qualified Vec here for clap, see https://github.com/clap-rs/clap/issues/4481 + pub warm_up_command: std::vec::Vec, /// Duration (e.g. 10m) to wait after warm up #[cfg_attr(feature = "clap", clap(long, global = true, value_name = "DURATION"))]