feat: support multiple skill flags to load multiple skills at CLI startup
This commit is contained in:
+14
-4
@@ -119,9 +119,11 @@ pub struct Cli {
|
|||||||
/// List all installed skills
|
/// List all installed skills
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub list_skills: bool,
|
pub list_skills: bool,
|
||||||
/// Open a skill in $EDITOR (creates with a scaffold if missing)
|
/// Pre-load an existing skill into the session (repeatable). If a single
|
||||||
|
/// `--skill <NAME>` is given and the skill doesn't exist, opens $EDITOR
|
||||||
|
/// with a scaffold to create it.
|
||||||
#[arg(long, value_name = "NAME")]
|
#[arg(long, value_name = "NAME")]
|
||||||
pub skill: Option<String>,
|
pub skill: Vec<String>,
|
||||||
/// Input text
|
/// Input text
|
||||||
#[arg(trailing_var_arg = true)]
|
#[arg(trailing_var_arg = true)]
|
||||||
text: Vec<String>,
|
text: Vec<String>,
|
||||||
@@ -309,8 +311,16 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_skill_flag_takes_name() {
|
fn parse_skill_flag_takes_name() {
|
||||||
assert_eq!(parse(&["--skill", "git-master"]).skill.as_deref(), Some("git-master"));
|
assert_eq!(parse(&["--skill", "git-master"]).skill, vec!["git-master"]);
|
||||||
assert!(parse(&[]).skill.is_none());
|
assert!(parse(&[]).skill.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_multiple_skill_flags_preserves_order() {
|
||||||
|
assert_eq!(
|
||||||
|
parse(&["--skill", "alpha", "--skill", "beta", "--skill", "gamma"]).skill,
|
||||||
|
vec!["alpha", "beta", "gamma"]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
+10
-4
@@ -197,13 +197,19 @@ async fn run(
|
|||||||
println!("{skills}");
|
println!("{skills}");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if let Some(name) = &cli.skill
|
if cli.skill.len() == 1 && !paths::has_skill(&cli.skill[0]) {
|
||||||
&& !paths::has_skill(name)
|
let name = &cli.skill[0];
|
||||||
{
|
|
||||||
let app = Arc::clone(&ctx.app.config);
|
let app = Arc::clone(&ctx.app.config);
|
||||||
ctx.upsert_skill(app.as_ref(), name)?;
|
ctx.upsert_skill(app.as_ref(), name)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
if cli.skill.len() > 1 {
|
||||||
|
for name in &cli.skill {
|
||||||
|
if !paths::has_skill(name) {
|
||||||
|
bail!("Skill '{name}' is not installed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if cli.dry_run {
|
if cli.dry_run {
|
||||||
update_app_config(&mut ctx, |app| app.dry_run = true);
|
update_app_config(&mut ctx, |app| app.dry_run = true);
|
||||||
@@ -317,7 +323,7 @@ async fn run(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(name) = &cli.skill {
|
for name in &cli.skill {
|
||||||
ctx.load_skill_repl(name, abort_signal.clone()).await?;
|
ctx.load_skill_repl(name, abort_signal.clone()).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user