feat: add configurable hostname options and outputs

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 17:39:46 -03:00
parent 2d1174266d
commit 430eafcf80

View File

@@ -15,8 +15,12 @@ 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();
// Add default value for "full" option // Set default values
final_options.insert("full".to_string(), serde_yaml::Value::Bool(true)); final_options.insert("hostname".to_string(), serde_yaml::Value::String("true".to_string()));
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 { if let Some(opts) = options {
for (key, value) in opts { for (key, value) in opts {
final_options.insert(key, value); final_options.insert(key, value);
@@ -25,10 +29,16 @@ impl HostnameMetaPlugin {
// Start with default outputs // Start with default outputs
let mut final_outputs = std::collections::HashMap::new(); let mut final_outputs = std::collections::HashMap::new();
let default_outputs = Self::default().default_outputs(); let default_outputs = vec![
"hostname".to_string(),
"hostname_full".to_string(),
"hostname_short".to_string(),
];
for output_name in default_outputs { for output_name in default_outputs {
final_outputs.insert(output_name.clone(), serde_yaml::Value::String(output_name)); final_outputs.insert(output_name.clone(), serde_yaml::Value::String(output_name));
} }
// Override with provided outputs
if let Some(outs) = outputs { if let Some(outs) = outputs {
for (key, value) in outs { for (key, value) in outs {
final_outputs.insert(key, value); final_outputs.insert(key, value);
@@ -168,32 +178,78 @@ impl MetaPlugin for HostnameMetaPlugin {
let mut metadata = Vec::new(); let mut metadata = Vec::new();
// Check if we should use full hostname or short hostname // Get the full hostname
let use_full = self.options.get("full")
.and_then(|v| v.as_bool())
.unwrap_or(true); // Default to true
log::debug!("HOSTNAME: use_full option: {:?}", use_full);
let full_hostname = self.get_hostname(); let full_hostname = self.get_hostname();
log::debug!("HOSTNAME: full hostname from system: {:?}", full_hostname); let short_hostname = full_hostname.split('.').next().unwrap_or(&full_hostname).to_string();
let hostname = if use_full { // Determine which hostnames to include based on options
full_hostname.clone() let hostname_enabled = match self.options.get("hostname") {
} else { Some(serde_yaml::Value::Bool(b)) => *b,
// Get short hostname (first part before the first dot) Some(serde_yaml::Value::String(s)) => match s.as_str() {
full_hostname.split('.').next().unwrap_or(&full_hostname).to_string() "true" => true,
"false" => false,
"full" => true,
"short" => true,
_ => true,
},
_ => true,
}; };
log::debug!("HOSTNAME: final hostname to use: {:?}", hostname); let hostname_full_enabled = self.options.get("hostname_full")
.and_then(|v| v.as_bool())
.unwrap_or(true);
let hostname_short_enabled = self.options.get("hostname_short")
.and_then(|v| v.as_bool())
.unwrap_or(true);
// Use process_metadata_outputs to handle output mapping // Determine which hostname value to use for the 'hostname' output
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( let hostname_value = match self.options.get("hostname") {
"hostname", Some(serde_yaml::Value::String(s)) => match s.as_str() {
hostname, "full" => full_hostname.clone(),
&self.outputs "short" => short_hostname.clone(),
) { _ => {
metadata.push(meta_data); // 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())
}
};
// Add hostname output if enabled
if hostname_enabled {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname",
hostname_value,
&self.outputs
) {
metadata.push(meta_data);
}
}
// Add hostname_full output if enabled
if hostname_full_enabled {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname_full",
full_hostname.clone(),
&self.outputs
) {
metadata.push(meta_data);
}
}
// Add hostname_short output if enabled
if hostname_short_enabled {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname_short",
short_hostname,
&self.outputs
) {
metadata.push(meta_data);
}
} }
// Mark as finalized since this plugin only needs to run once // Mark as finalized since this plugin only needs to run once
@@ -214,7 +270,11 @@ impl MetaPlugin for HostnameMetaPlugin {
} }
fn default_outputs(&self) -> Vec<String> { fn default_outputs(&self) -> Vec<String> {
vec!["hostname".to_string()] vec![
"hostname".to_string(),
"hostname_full".to_string(),
"hostname_short".to_string(),
]
} }