Skip to content

Commit

Permalink
fix: parse commands given by arg or env using shell_words (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome authored Aug 14, 2024
1 parent 3db5ace commit cfdff01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 }
Expand Down
23 changes: 17 additions & 6 deletions crates/core/src/repository.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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<String>,
// 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<String>,

/// Don't use a cache.
#[cfg_attr(feature = "clap", clap(long, global = true, env = "RUSTIC_NO_CACHE"))]
Expand All @@ -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<String>,
// 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<String>,

/// Duration (e.g. 10m) to wait after warm up
#[cfg_attr(feature = "clap", clap(long, global = true, value_name = "DURATION"))]
Expand Down

0 comments on commit cfdff01

Please sign in to comment.