fix: include full recipe parameter details in load/discovery output (#9233)
Signed-off-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::config::{Config, GooseMode};
|
||||
use crate::providers;
|
||||
use crate::recipe::build_recipe::build_recipe_from_template;
|
||||
use crate::recipe::local_recipes::load_local_recipe_file;
|
||||
use crate::recipe::{Recipe, Settings, RECIPE_FILE_EXTENSIONS};
|
||||
use crate::recipe::{Recipe, RecipeParameter, Settings, RECIPE_FILE_EXTENSIONS};
|
||||
use crate::session::extension_data::EnabledExtensionsState;
|
||||
use crate::session::SessionType;
|
||||
use crate::sources::parse_frontmatter;
|
||||
@@ -647,7 +647,16 @@ impl SummonClient {
|
||||
|
||||
match load_local_recipe_file(&sr.path) {
|
||||
Ok(recipe_file) => match Recipe::from_content(&recipe_file.content) {
|
||||
Ok(recipe) => recipe.instructions.unwrap_or_default(),
|
||||
Ok(recipe) => {
|
||||
let mut content = recipe.instructions.unwrap_or_default();
|
||||
if let Some(params) = &recipe.parameters {
|
||||
if !params.is_empty() {
|
||||
content.push_str("\n\n");
|
||||
content.push_str(&Self::format_parameters(params));
|
||||
}
|
||||
}
|
||||
content
|
||||
}
|
||||
Err(_) => recipe_file.content,
|
||||
},
|
||||
Err(_) => String::new(),
|
||||
@@ -711,10 +720,8 @@ impl SummonClient {
|
||||
let mut desc = recipe.description.clone();
|
||||
|
||||
if let Some(params) = &recipe.parameters {
|
||||
let param_names: Vec<&str> = params.iter().map(|p| p.key.as_str()).collect();
|
||||
if !param_names.is_empty() {
|
||||
let params_str = param_names.join(", ");
|
||||
desc = format!("{} (params: {})", desc, params_str);
|
||||
if !params.is_empty() {
|
||||
desc = format!("{}\n{}", desc, Self::format_parameters(params));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,6 +732,24 @@ impl SummonClient {
|
||||
format!("Subrecipe from {}", sr.path)
|
||||
}
|
||||
|
||||
fn format_parameters(params: &[RecipeParameter]) -> String {
|
||||
let mut out = String::from("Parameters:");
|
||||
for p in params {
|
||||
let mut detail = format!("\n - {} ({}, {})", p.key, p.input_type, p.requirement);
|
||||
if let Some(default) = &p.default {
|
||||
detail.push_str(&format!(", default: \"{}\"", default));
|
||||
}
|
||||
if let Some(options) = &p.options {
|
||||
if !options.is_empty() {
|
||||
detail.push_str(&format!(", options: [{}]", options.join(", ")));
|
||||
}
|
||||
}
|
||||
detail.push_str(&format!(": {}", p.description));
|
||||
out.push_str(&detail);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
async fn handle_load(
|
||||
&self,
|
||||
session_id: &str,
|
||||
|
||||
Reference in New Issue
Block a user