feat: Add --digest CLI option to select digest type
This commit is contained in:
@@ -105,9 +105,17 @@ struct ItemArgs {
|
|||||||
#[arg(help("Set metadata for the item using the format KEY=[VALUE], the metadata will be removed if VALUE is not provided"))]
|
#[arg(help("Set metadata for the item using the format KEY=[VALUE], the metadata will be removed if VALUE is not provided"))]
|
||||||
meta: Vec<KeyValue>,
|
meta: Vec<KeyValue>,
|
||||||
|
|
||||||
|
#[arg(help_heading("Item Options"), short, long, env("KEEP_DIGEST"))]
|
||||||
|
#[arg(help("Digest algorithm to use when saving items"))]
|
||||||
|
digest: Option<String>,
|
||||||
|
|
||||||
#[arg(help_heading("Item Options"), short, long, env("KEEP_COMPRESSION"))]
|
#[arg(help_heading("Item Options"), short, long, env("KEEP_COMPRESSION"))]
|
||||||
#[arg(help("Compression algorithm to use when saving items"))]
|
#[arg(help("Compression algorithm to use when saving items"))]
|
||||||
compression: Option<String>,
|
compression: Option<String>,
|
||||||
|
|
||||||
|
#[arg(help_heading("Item Options"), short, long, env("KEEP_DIGEST"))]
|
||||||
|
#[arg(help("Digest algorithm to use when saving items"))]
|
||||||
|
digest: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
|||||||
@@ -35,6 +35,13 @@ pub fn mode_save(
|
|||||||
tags.push("none".to_string());
|
tags.push("none".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the digest type to use
|
||||||
|
let digest_name = args
|
||||||
|
.item
|
||||||
|
.digest
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(DigestType::Sha256.to_string());
|
||||||
|
|
||||||
let compression_name = args
|
let compression_name = args
|
||||||
.item
|
.item
|
||||||
.compression
|
.compression
|
||||||
@@ -55,7 +62,8 @@ pub fn mode_save(
|
|||||||
debug!("MAIN: Compression type: {}", compression_type);
|
debug!("MAIN: Compression type: {}", compression_type);
|
||||||
|
|
||||||
// Create a new digest engine
|
// Create a new digest engine
|
||||||
let digest_type = DigestType::Sha256;
|
let digest_type = DigestType::from_str(&digest_name)
|
||||||
|
.unwrap_or(DigestType::Sha256);
|
||||||
let mut digest_engine = get_engine(digest_type);
|
let mut digest_engine = get_engine(digest_type);
|
||||||
|
|
||||||
let mut item = db::Item {
|
let mut item = db::Item {
|
||||||
|
|||||||
31
src/tests.rs
31
src/tests.rs
@@ -57,6 +57,37 @@ mod tests {
|
|||||||
cmd,
|
cmd,
|
||||||
output.status
|
output.status
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Test with digest option
|
||||||
|
let cmd = format!("echo {} | {} --digest sha256 -c none none", INPUT_A, env);
|
||||||
|
println!("RUNNING: {}", cmd);
|
||||||
|
let output = run_sh(cmd.as_str());
|
||||||
|
assert!(
|
||||||
|
output.status.success(),
|
||||||
|
"Command failed: {} {}",
|
||||||
|
cmd,
|
||||||
|
output.status
|
||||||
|
);
|
||||||
|
|
||||||
|
let cmd = format!("echo {} | {} --digest md5 -c none none", INPUT_A, env);
|
||||||
|
println!("RUNNING: {}", cmd);
|
||||||
|
let output = run_sh(cmd.as_str());
|
||||||
|
assert!(
|
||||||
|
output.status.success(),
|
||||||
|
"Command failed: {} {}",
|
||||||
|
cmd,
|
||||||
|
output.status
|
||||||
|
);
|
||||||
|
|
||||||
|
let cmd = format!("echo {} | {} --digest program -p md5sum -c none none", INPUT_A, env);
|
||||||
|
println!("RUNNING: {}", cmd);
|
||||||
|
let output = run_sh(cmd.as_str());
|
||||||
|
assert!(
|
||||||
|
output.status.success(),
|
||||||
|
"Command failed: {} {}",
|
||||||
|
cmd,
|
||||||
|
output.status
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to check if a file exists in the data directory
|
// Helper function to check if a file exists in the data directory
|
||||||
|
|||||||
Reference in New Issue
Block a user