From 249f852a3faf8fcbde03bbc2cf7d9240a72940e3 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Wed, 27 Dec 2023 21:40:06 -0500 Subject: [PATCH] feat(init): Adding new subcommand --- src/bin/ublue.rs | 6 ++++++ src/init.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/bin/ublue.rs b/src/bin/ublue.rs index ef98779..ff8b70e 100644 --- a/src/bin/ublue.rs +++ b/src/bin/ublue.rs @@ -27,6 +27,9 @@ enum CommandArgs { #[cfg(feature = "init")] Init(init::InitCommand), + #[cfg(feature = "init")] + New(init::NewCommand), + /// Build an image from a recipe #[cfg(feature = "build")] Build(build::BuildCommand), @@ -48,6 +51,9 @@ fn main() -> Result<()> { #[cfg(feature = "init")] CommandArgs::Init(command) => command.run()?, + #[cfg(feature = "init")] + CommandArgs::New(command) => command.run()?, + #[cfg(feature = "build")] CommandArgs::Build(command) => command.run()?, } diff --git a/src/init.rs b/src/init.rs index d50c5c4..b403b08 100644 --- a/src/init.rs +++ b/src/init.rs @@ -8,11 +8,22 @@ const GITLAB_CI_FILE: &'static str = include_str!("../templates/init/gitlab-ci.y const RECIPE_FILE: &'static str = include_str!("../templates/init/recipe.yml.tera"); const LICENSE_FILE: &'static str = include_str!("../LICENSE"); +#[derive(Debug, Clone, Default, Args, TypedBuilder)] +pub struct NewInitCommon { + #[builder(default)] + no_git: bool, +} + #[derive(Debug, Clone, Args, TypedBuilder)] pub struct InitCommand { /// The directory to extract the files into. Defaults to the current directory #[arg()] + #[builder(setter(strip_option, into), default)] dir: Option, + + #[clap(flatten)] + #[builder(default)] + common: NewInitCommon, } impl InitCommand { @@ -42,3 +53,24 @@ impl InitCommand { let post_scripts_dir = scripts_dir.join("post/"); } } + +#[derive(Debug, Clone, Args, TypedBuilder)] +pub struct NewCommand { + #[arg()] + dir: PathBuf, + + #[clap(flatten)] + common: NewInitCommon, +} + +impl NewCommand { + pub fn run(&self) -> Result<()> { + InitCommand::builder() + .dir(self.dir.clone()) + .common(self.common.clone()) + .build() + .run()?; + + Ok(()) + } +}