From e2feef1c27635557b9b602558aebe9944f3d6295 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 29 Oct 2023 00:13:45 +0200 Subject: [PATCH] feat: with multiple args Signed-off-by: kjuulh --- cuddle/src/cli/subcommands/render_template.rs | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/cuddle/src/cli/subcommands/render_template.rs b/cuddle/src/cli/subcommands/render_template.rs index 08a91e4..d1699bd 100644 --- a/cuddle/src/cli/subcommands/render_template.rs +++ b/cuddle/src/cli/subcommands/render_template.rs @@ -1,32 +1,37 @@ use std::{path::PathBuf, str::FromStr}; -use clap::{Arg, ArgMatches, Command}; +use clap::{Arg, ArgGroup, ArgMatches, Command}; use crate::{cli::CuddleCli, model::CuddleVariable}; +const DESTINATION: &'static str = "destination is the output path of the template once done, but default .tmpl is stripped and the normal file extension is used. this can be overwritten if a file path is entered instead. I.e. (/some/file/name.txt)"; +const TEMPLATE_FILE: &'static str = "template-file is the input file path of the .tmpl file (or inferred) that you would like to render"; + pub fn build_command(root_cmd: Command) -> Command { root_cmd.subcommand( - Command::new("render_template") - .about("renders a jinja compatible template") - .args(&[ - Arg::new("template-file") - .alias("template") - .short('t') - .long("template-file") - .required(true) - .action(clap::ArgAction::Set).long_help("template-file is the input file path of the .tmpl file (or inferred) that you would like to render"), - Arg::new("destination") - .alias("dest") - .short('d') - .long("destination") - .required(true) - .action(clap::ArgAction::Set) - .long_help("destination is the output path of the template once done, but default .tmpl is stripped and the normal file extension is used. this can be overwritten if a file path is entered instead. I.e. (/some/file/name.txt)"), - Arg::new("extra-var") - .long("extra-var") - .required(false) - .action(clap::ArgAction::Set), - ])) + Command::new("render_template") + .about("renders a jinja compatible template") + .args(&[ + Arg::new("template-file") + .alias("template") + .short('t') + .long("template-file") + .required(true) + .action(clap::ArgAction::Set) + .long_help(TEMPLATE_FILE), + Arg::new("destination") + .alias("dest") + .short('d') + .long("destination") + .required(true) + .action(clap::ArgAction::Set) + .long_help(DESTINATION), + Arg::new("extra-var") + .long("extra-var") + .required(false) + .action(clap::ArgAction::Append), + ]), + ) } pub struct RenderTemplateCommand {