feat: make hostname option boolean-only and simplify hostname output logic

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-27 23:02:48 -03:00
parent 21edfbd633
commit 9e3df98e79

View File

@@ -25,16 +25,16 @@ impl HostnameMetaPlugin {
) -> HostnameMetaPlugin { ) -> HostnameMetaPlugin {
// Start with default options // Start with default options
let mut final_options = std::collections::HashMap::new(); let mut final_options = std::collections::HashMap::new();
// Set default values // Set default values - hostname is now boolean only
final_options.insert("hostname".to_string(), serde_yaml::Value::String("true".to_string())); final_options.insert("hostname".to_string(), serde_yaml::Value::Bool(true));
final_options.insert("hostname_full".to_string(), serde_yaml::Value::Bool(true)); final_options.insert("hostname_full".to_string(), serde_yaml::Value::Bool(true));
final_options.insert("hostname_short".to_string(), serde_yaml::Value::Bool(true)); final_options.insert("hostname_short".to_string(), serde_yaml::Value::Bool(true));
// Override with provided options // Override with provided options
if let Some(opts) = options { if let Some(opts) = options {
for (key, value) in opts { for (key, value) in opts {
// Handle "false" string values by converting them to Bool(false) // Convert string "true"/"false" to boolean for hostname option
if key == "hostname" || key == "hostname_full" || key == "hostname_short" { if key == "hostname" {
if let serde_yaml::Value::String(s) = &value { if let serde_yaml::Value::String(s) = &value {
if s == "false" { if s == "false" {
final_options.insert(key, serde_yaml::Value::Bool(false)); final_options.insert(key, serde_yaml::Value::Bool(false));
@@ -50,17 +50,9 @@ impl HostnameMetaPlugin {
} }
// Determine which outputs are enabled based on options // Determine which outputs are enabled based on options
let hostname_enabled = match final_options.get("hostname") { let hostname_enabled = final_options.get("hostname")
Some(serde_yaml::Value::Bool(b)) => *b, .and_then(|v| v.as_bool())
Some(serde_yaml::Value::String(s)) => match s.as_str() { .unwrap_or(true);
"true" => true,
"false" => false,
"full" => true,
"short" => true,
_ => true,
},
_ => true,
};
let hostname_full_enabled = final_options.get("hostname_full") let hostname_full_enabled = final_options.get("hostname_full")
.and_then(|v| v.as_bool()) .and_then(|v| v.as_bool())
@@ -252,20 +244,9 @@ impl MetaPlugin for HostnameMetaPlugin {
let short_hostname = full_hostname.split('.').next().unwrap_or(&full_hostname).to_string(); let short_hostname = full_hostname.split('.').next().unwrap_or(&full_hostname).to_string();
// Determine which hostnames to include based on options // Determine which hostnames to include based on options
let hostname_enabled = match self.options.get("hostname") { let hostname_enabled = self.options.get("hostname")
Some(serde_yaml::Value::Bool(b)) => *b, .and_then(|v| v.as_bool())
Some(serde_yaml::Value::String(s)) => match s.as_str() { .unwrap_or(true);
"true" => true,
"false" => false,
"full" => true,
"short" => true,
_ => true,
},
_ => true,
};
// Ensure that if hostname is explicitly set to false, it's disabled
// This handles cases where it might be set to "false" string which we converted above
let hostname_full_enabled = self.options.get("hostname_full") let hostname_full_enabled = self.options.get("hostname_full")
.and_then(|v| v.as_bool()) .and_then(|v| v.as_bool())
@@ -275,20 +256,11 @@ impl MetaPlugin for HostnameMetaPlugin {
.and_then(|v| v.as_bool()) .and_then(|v| v.as_bool())
.unwrap_or(true); .unwrap_or(true);
// Determine which hostname value to use for the 'hostname' output // Always use gethostname() for the 'hostname' output when enabled
let hostname_value = match self.options.get("hostname") { let hostname_value = if hostname_enabled {
Some(serde_yaml::Value::String(s)) => match s.as_str() {
"full" => full_hostname.clone(),
"short" => short_hostname.clone(),
_ => {
// For 'true' or any other value, use gethostname()
gethostname::gethostname().into_string().unwrap_or_else(|_| "unknown".to_string()) gethostname::gethostname().into_string().unwrap_or_else(|_| "unknown".to_string())
} } else {
}, String::new()
_ => {
// Default behavior
gethostname::gethostname().into_string().unwrap_or_else(|_| "unknown".to_string())
}
}; };
// Update outputs based on enabled status // Update outputs based on enabled status