feat(init): Adding new subcommand
This commit is contained in:
parent
556652f92a
commit
249f852a3f
2 changed files with 38 additions and 0 deletions
|
|
@ -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()?,
|
||||
}
|
||||
|
|
|
|||
32
src/init.rs
32
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<PathBuf>,
|
||||
|
||||
#[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(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue