From 04e8baeefc55fba31473a7933af1376883cdb815 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 17 Jun 2023 13:05:17 +0200 Subject: [PATCH] feat: with variables Signed-off-by: kjuulh --- cuddle_cli/src/cli/subcommands/init.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cuddle_cli/src/cli/subcommands/init.rs b/cuddle_cli/src/cli/subcommands/init.rs index 12848cb..24cf3ac 100644 --- a/cuddle_cli/src/cli/subcommands/init.rs +++ b/cuddle_cli/src/cli/subcommands/init.rs @@ -22,7 +22,8 @@ pub fn build_command(root_cmd: Command, _cli: CuddleCli) -> Command { .about("init bootstraps a repository from a template") .arg(repo_url) .arg(clap::Arg::new("name")) - .arg(clap::Arg::new("path")); + .arg(clap::Arg::new("path")) + .arg(clap::Arg::new("value").short('v').long("value")); root_cmd.subcommand(execute_cmd) } @@ -31,6 +32,10 @@ pub fn execute_init(exe_submatch: &ArgMatches, _cli: CuddleCli) -> anyhow::Resul let repo = exe_submatch.get_one::("repo").unwrap(); let name = exe_submatch.get_one::("name"); let path = exe_submatch.get_one::("path"); + let values = exe_submatch + .get_many::("value") + .unwrap_or_default() + .collect::>(); tracing::info!("Downloading: {}", repo); @@ -134,7 +139,15 @@ pub fn execute_init(exe_submatch: &ArgMatches, _cli: CuddleCli) -> anyhow::Resul { if let Some(ref mut prompt) = template.prompt { - for (name, prompt) in prompt { + 'prompt: for (name, prompt) in prompt { + for value in &values { + if let Some((value_name, value_content)) = value.split_once("=") { + if value_name == name { + prompt.value = value_content.to_string(); + continue 'prompt; + } + } + } let value = inquire::Text::new(&name) .with_help_message(&prompt.description) .prompt()?;