Skip to content

Commit

Permalink
feat: update conflate dependency to version 0.3.2 and refactor merge …
Browse files Browse the repository at this point in the history
…strategies

Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Nov 20, 2024
1 parent 190fc97 commit de56285
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ dbg-test test_name $RUST_LOG="debug":
build-docker version="0.4.0":
podman build containers --build-arg RUSTIC_SERVER_VERSION=v{{ version }} --format docker --tag rustic_server:v{{ version }}

server-up:
server-up: build-docker
uv --directory containers run podman-compose -f docker-compose.yml up --detach

server-down:
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ axum-range = "0.4"
axum-server = { version = "0.7", features = ["tls-rustls"] }
chrono = { version = "0.4.38", features = ["serde"] }
clap = { version = "4", features = ["derive", "env", "wrap_help"] }
conflate = "0.3.1"
conflate = "0.3.2"
displaydoc = "0.2"
# enum_dispatch = "0.3.12"
futures = "0.3"
Expand Down
25 changes: 9 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ pub struct RusticServerConfig {
pub log: LogSettings,
}

/// Overwrite the left value with the right value if the right value is `Some`.
fn overwrite_with_some<T>(left: &mut Option<T>, right: Option<T>) {
if right.is_some() {
*left = right;
}
}

/// Overwrite the left value with the right value unconditionally.
#[allow(dead_code)]
fn overwrite_left<T>(left: &mut T, right: T) {
Expand All @@ -64,7 +57,7 @@ fn overwrite_left<T>(left: &mut T, right: T) {
pub struct ConnectionSettings {
/// IP address and port to bind to
#[arg(long, env = "RUSTIC_SERVER_LISTEN")]
#[merge(strategy = overwrite_with_some)]
#[merge(strategy = conflate::option::overwrite_with_some)]
pub listen: Option<SocketAddr>,
}

Expand All @@ -87,7 +80,7 @@ pub struct LogSettings {
// We don't want to expose this to the CLI, as we use the global verbose flag there
#[clap(skip)]
#[serde(skip_serializing_if = "Option::is_none")]
#[merge(strategy = overwrite_with_some)]
#[merge(strategy = conflate::option::overwrite_with_some)]
pub log_level: Option<String>,

/// Write HTTP requests in the combined log format to the specified filename
Expand All @@ -96,7 +89,7 @@ pub struct LogSettings {
/// If `None`, logging will be disabled or will use a default logging mechanism.
#[arg(long = "log", env = "RUSTIC_SERVER_LOG_FILE")]
#[serde(skip_serializing_if = "Option::is_none")]
#[merge(strategy = overwrite_with_some)]
#[merge(strategy = conflate::option::overwrite_with_some)]
pub log_file: Option<PathBuf>,
}

Expand All @@ -118,13 +111,13 @@ pub struct StorageSettings {
/// By default the server persists backup data in the OS temporary directory
/// (/tmp/rustic on Linux/BSD and others, in %TEMP%\\rustic in Windows, etc).
#[arg(long = "path", env = "RUSTIC_SERVER_DATA_DIR")]
#[merge(strategy = overwrite_with_some)]
#[merge(strategy = conflate::option::overwrite_with_some)]
pub data_dir: Option<PathBuf>,

/// Optional maximum size (quota) of a repository in bytes
#[arg(long = "max-size", env = "RUSTIC_SERVER_QUOTA")]
#[serde(skip_serializing_if = "Option::is_none")]
#[merge(strategy = overwrite_with_some)]
#[merge(strategy = conflate::option::overwrite_with_some)]
pub quota: Option<usize>,
}

Expand Down Expand Up @@ -167,12 +160,12 @@ pub struct TlsSettings {

/// Optional path to the TLS key file
#[arg(long, requires = "disable_tls", env = "RUSTIC_SERVER_TLS_KEY")]
#[merge(strategy = overwrite_with_some)]
#[merge(strategy = conflate::option::overwrite_with_some)]
pub tls_key: Option<PathBuf>,

/// Optional path to the TLS certificate file
#[arg(long, requires = "disable_tls", env = "RUSTIC_SERVER_TLS_CERT")]
#[merge(strategy = overwrite_with_some)]
#[merge(strategy = conflate::option::overwrite_with_some)]
pub tls_cert: Option<PathBuf>,
}

Expand Down Expand Up @@ -205,7 +198,7 @@ pub struct HtpasswdSettings {
/// Optional location of .htpasswd file (default: "<data directory>/.htpasswd")
#[arg(long, env = "RUSTIC_SERVER_HTPASSWD_FILE")]
#[serde(skip_serializing_if = "Option::is_none")]
#[merge(strategy = overwrite_with_some)]
#[merge(strategy = conflate::option::overwrite_with_some)]
pub htpasswd_file: Option<PathBuf>,
}

Expand Down Expand Up @@ -276,7 +269,7 @@ pub struct AclSettings {
/// (default: "<data directory>/acl.toml")
#[arg(long, requires = "private_repos", env = "RUSTIC_SERVER_ACL_PATH")]
#[serde(skip_serializing_if = "Option::is_none")]
#[merge(strategy = overwrite_with_some)]
#[merge(strategy = conflate::option::overwrite_with_some)]
pub acl_path: Option<PathBuf>,
}

Expand Down

0 comments on commit de56285

Please sign in to comment.