fix: ensure outputs are properly disabled in constructors
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -87,16 +87,6 @@ impl DigestMetaPlugin {
|
|||||||
) -> DigestMetaPlugin {
|
) -> DigestMetaPlugin {
|
||||||
let mut plugin = DigestMetaPlugin::default();
|
let mut plugin = DigestMetaPlugin::default();
|
||||||
|
|
||||||
// Set default outputs
|
|
||||||
let default_outputs = vec![
|
|
||||||
("digest_md5".to_string(), serde_yaml::Value::String("digest_md5".to_string())),
|
|
||||||
("digest_sha256".to_string(), serde_yaml::Value::String("digest_sha256".to_string())),
|
|
||||||
("digest_sha512".to_string(), serde_yaml::Value::String("digest_sha512".to_string())),
|
|
||||||
];
|
|
||||||
for (key, value) in default_outputs {
|
|
||||||
plugin.outputs.insert(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply provided options
|
// Apply provided options
|
||||||
if let Some(opts) = options {
|
if let Some(opts) = options {
|
||||||
for (key, value) in opts {
|
for (key, value) in opts {
|
||||||
@@ -104,30 +94,54 @@ impl DigestMetaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply provided outputs
|
// Determine the selected method
|
||||||
if let Some(outs) = outputs {
|
let method = if let Some(method_value) = plugin.options.get("method") {
|
||||||
for (key, value) in outs {
|
|
||||||
plugin.outputs.insert(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the hasher based on the method option
|
|
||||||
if let Some(method_value) = plugin.options.get("method") {
|
|
||||||
if let Some(method_str) = method_value.as_str() {
|
if let Some(method_str) = method_value.as_str() {
|
||||||
plugin.hasher = match method_str {
|
match method_str {
|
||||||
|
"md5" => "md5",
|
||||||
|
"sha256" => "sha256",
|
||||||
|
"sha512" => "sha512",
|
||||||
|
_ => "sha256",
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"sha256"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"sha256"
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initialize the hasher based on the method
|
||||||
|
plugin.hasher = match method {
|
||||||
"md5" => Some(Hasher::Md5(md5::Context::new())),
|
"md5" => Some(Hasher::Md5(md5::Context::new())),
|
||||||
"sha256" => Some(Hasher::Sha256(Sha256::new())),
|
"sha256" => Some(Hasher::Sha256(Sha256::new())),
|
||||||
"sha512" => Some(Hasher::Sha512(Sha512::new())),
|
"sha512" => Some(Hasher::Sha512(Sha512::new())),
|
||||||
_ => None,
|
_ => Some(Hasher::Sha256(Sha256::new())),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add the method to options so it shows up in the status
|
||||||
|
plugin.options.insert("method".to_string(), serde_yaml::Value::String(method.to_string()));
|
||||||
|
|
||||||
|
// Set outputs based on the selected method
|
||||||
|
// Only the selected method's output should be enabled, others should be None
|
||||||
|
let all_outputs = vec!["digest_md5", "digest_sha256", "digest_sha512"];
|
||||||
|
for output_name in all_outputs {
|
||||||
|
if output_name == format!("digest_{}", method) {
|
||||||
|
plugin.outputs.insert(output_name.to_string(), serde_yaml::Value::String(output_name.to_string()));
|
||||||
|
} else {
|
||||||
|
plugin.outputs.insert(output_name.to_string(), serde_yaml::Value::Null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to sha256 if no valid method is specified
|
// Apply provided outputs, but only for enabled outputs
|
||||||
if plugin.hasher.is_none() {
|
if let Some(outs) = outputs {
|
||||||
plugin.hasher = Some(Hasher::Sha256(Sha256::new()));
|
for (key, value) in outs {
|
||||||
// Add the default method to options so it shows up in the status
|
// Only update if the output is not disabled (not None)
|
||||||
plugin.options.insert("method".to_string(), serde_yaml::Value::String("sha256".to_string()));
|
if let Some(current_value) = plugin.outputs.get_mut(&key) {
|
||||||
|
if !current_value.is_null() {
|
||||||
|
*current_value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin
|
plugin
|
||||||
|
|||||||
@@ -39,21 +39,69 @@ impl HostnameMetaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start with default outputs
|
// Determine which outputs are enabled based on options
|
||||||
|
let hostname_enabled = match final_options.get("hostname") {
|
||||||
|
Some(serde_yaml::Value::Bool(b)) => *b,
|
||||||
|
Some(serde_yaml::Value::String(s)) => match s.as_str() {
|
||||||
|
"true" => true,
|
||||||
|
"false" => false,
|
||||||
|
"full" => true,
|
||||||
|
"short" => true,
|
||||||
|
_ => true,
|
||||||
|
},
|
||||||
|
_ => true,
|
||||||
|
};
|
||||||
|
|
||||||
|
let hostname_full_enabled = final_options.get("hostname_full")
|
||||||
|
.and_then(|v| v.as_bool())
|
||||||
|
.unwrap_or(true);
|
||||||
|
|
||||||
|
let hostname_short_enabled = final_options.get("hostname_short")
|
||||||
|
.and_then(|v| v.as_bool())
|
||||||
|
.unwrap_or(true);
|
||||||
|
|
||||||
|
// Start with default outputs, setting disabled ones to None
|
||||||
let mut final_outputs = std::collections::HashMap::new();
|
let mut final_outputs = std::collections::HashMap::new();
|
||||||
let default_outputs = vec![
|
|
||||||
"hostname".to_string(),
|
// Handle hostname output
|
||||||
"hostname_full".to_string(),
|
if hostname_enabled {
|
||||||
"hostname_short".to_string(),
|
final_outputs.insert("hostname".to_string(), serde_yaml::Value::String("hostname".to_string()));
|
||||||
];
|
} else {
|
||||||
for output_name in default_outputs {
|
final_outputs.insert("hostname".to_string(), serde_yaml::Value::Null);
|
||||||
final_outputs.insert(output_name.clone(), serde_yaml::Value::String(output_name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override with provided outputs
|
// Handle hostname_full output
|
||||||
|
if hostname_full_enabled {
|
||||||
|
final_outputs.insert("hostname_full".to_string(), serde_yaml::Value::String("hostname_full".to_string()));
|
||||||
|
} else {
|
||||||
|
final_outputs.insert("hostname_full".to_string(), serde_yaml::Value::Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle hostname_short output
|
||||||
|
if hostname_short_enabled {
|
||||||
|
final_outputs.insert("hostname_short".to_string(), serde_yaml::Value::String("hostname_short".to_string()));
|
||||||
|
} else {
|
||||||
|
final_outputs.insert("hostname_short".to_string(), serde_yaml::Value::Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override with provided outputs, but only if they're enabled
|
||||||
if let Some(outs) = outputs {
|
if let Some(outs) = outputs {
|
||||||
for (key, value) in outs {
|
for (key, value) in outs {
|
||||||
|
// Only add if the output is enabled
|
||||||
|
match key.as_str() {
|
||||||
|
"hostname" => if hostname_enabled {
|
||||||
final_outputs.insert(key, value);
|
final_outputs.insert(key, value);
|
||||||
|
},
|
||||||
|
"hostname_full" => if hostname_full_enabled {
|
||||||
|
final_outputs.insert(key, value);
|
||||||
|
},
|
||||||
|
"hostname_short" => if hostname_short_enabled {
|
||||||
|
final_outputs.insert(key, value);
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
final_outputs.insert(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user