feat: Add --digest CLI option to select digest type

This commit is contained in:
Andrew Phillips (aider)
2025-05-12 19:10:12 -03:00
parent a3a4c49e31
commit b1bfa7110b
3 changed files with 48 additions and 1 deletions

View File

@@ -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"))]
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("Compression algorithm to use when saving items"))]
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)]

View File

@@ -35,6 +35,13 @@ pub fn mode_save(
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
.item
.compression
@@ -55,7 +62,8 @@ pub fn mode_save(
debug!("MAIN: Compression type: {}", compression_type);
// 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 item = db::Item {

View File

@@ -57,6 +57,37 @@ mod tests {
cmd,
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