From 9e3df98e79ece074d698a468f5b7070a1093d4ed Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 27 Aug 2025 23:02:48 -0300 Subject: [PATCH] feat: make hostname option boolean-only and simplify hostname output logic Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- src/meta_plugin/hostname.rs | 58 ++++++++++--------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/src/meta_plugin/hostname.rs b/src/meta_plugin/hostname.rs index d02a61c..b7baa39 100644 --- a/src/meta_plugin/hostname.rs +++ b/src/meta_plugin/hostname.rs @@ -25,16 +25,16 @@ impl HostnameMetaPlugin { ) -> HostnameMetaPlugin { // Start with default options let mut final_options = std::collections::HashMap::new(); - // Set default values - final_options.insert("hostname".to_string(), serde_yaml::Value::String("true".to_string())); + // Set default values - hostname is now boolean only + 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_short".to_string(), serde_yaml::Value::Bool(true)); // Override with provided options if let Some(opts) = options { for (key, value) in opts { - // Handle "false" string values by converting them to Bool(false) - if key == "hostname" || key == "hostname_full" || key == "hostname_short" { + // Convert string "true"/"false" to boolean for hostname option + if key == "hostname" { if let serde_yaml::Value::String(s) = &value { if s == "false" { final_options.insert(key, serde_yaml::Value::Bool(false)); @@ -50,17 +50,9 @@ impl HostnameMetaPlugin { } // 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_enabled = final_options.get("hostname") + .and_then(|v| v.as_bool()) + .unwrap_or(true); let hostname_full_enabled = final_options.get("hostname_full") .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(); // Determine which hostnames to include based on options - let hostname_enabled = match self.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, - }; - - // 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_enabled = self.options.get("hostname") + .and_then(|v| v.as_bool()) + .unwrap_or(true); let hostname_full_enabled = self.options.get("hostname_full") .and_then(|v| v.as_bool()) @@ -275,20 +256,11 @@ impl MetaPlugin for HostnameMetaPlugin { .and_then(|v| v.as_bool()) .unwrap_or(true); - // Determine which hostname value to use for the 'hostname' output - let hostname_value = match self.options.get("hostname") { - 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()) - } - }, - _ => { - // Default behavior - gethostname::gethostname().into_string().unwrap_or_else(|_| "unknown".to_string()) - } + // Always use gethostname() for the 'hostname' output when enabled + let hostname_value = if hostname_enabled { + gethostname::gethostname().into_string().unwrap_or_else(|_| "unknown".to_string()) + } else { + String::new() }; // Update outputs based on enabled status