chore: Switch to using typed builders
This commit is contained in:
parent
e9cfc8ae06
commit
aa86f48a5d
6 changed files with 39 additions and 19 deletions
12
src/build.rs
12
src/build.rs
|
|
@ -7,12 +7,12 @@ use std::{
|
|||
use anyhow::{anyhow, bail, Result};
|
||||
use chrono::Local;
|
||||
use clap::Args;
|
||||
use derive_builder::Builder;
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
use crate::{module_recipe::Recipe, ops, template::TemplateCommand};
|
||||
|
||||
#[derive(Debug, Clone, Args, Builder)]
|
||||
#[derive(Debug, Clone, Args, TypedBuilder)]
|
||||
pub struct BuildCommand {
|
||||
/// The recipe file to build an image
|
||||
#[arg()]
|
||||
|
|
@ -63,8 +63,8 @@ impl BuildCommand {
|
|||
if let Err(e) = TemplateCommand::builder()
|
||||
.recipe(self.recipe.clone())
|
||||
.containerfile(self.containerfile.clone())
|
||||
.output(Some(PathBuf::from("Containerfile")))
|
||||
.build()?
|
||||
.output(PathBuf::from("Containerfile"))
|
||||
.build()
|
||||
.run()
|
||||
{
|
||||
error!("Failed to template file: {e}");
|
||||
|
|
@ -105,10 +105,6 @@ impl BuildCommand {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn builder() -> BuildCommandBuilder {
|
||||
BuildCommandBuilder::default()
|
||||
}
|
||||
|
||||
fn generate_tags(&self, recipe: &Recipe) -> Vec<String> {
|
||||
debug!("Generating image tags for {}", &recipe.name);
|
||||
trace!("BuildCommand::generate_tags({recipe:#?})");
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use anyhow::Result;
|
||||
use clap::Args;
|
||||
use derive_builder::Builder;
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
const GITLAB_CI_FILE: &'static str = include_str!("../templates/init/gitlab-ci.yml.tera");
|
||||
const RECIPE_FILE: &'static str = include_str!("../templates/init/recipe.yml.tera");
|
||||
const LICENSE_FILE: &'static str = include_str!("../LICENSE");
|
||||
|
||||
#[derive(Debug, Clone, Args, Builder)]
|
||||
#[derive(Debug, Clone, Args, TypedBuilder)]
|
||||
pub struct InitCommand {
|
||||
/// The directory to extract the files into. Defaults to the current directory
|
||||
#[arg()]
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ use std::{
|
|||
|
||||
use anyhow::Result;
|
||||
use clap::Args;
|
||||
use derive_builder::Builder;
|
||||
use log::{debug, error, info, trace};
|
||||
use tera::{Context, Tera};
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
use crate::module_recipe::Recipe;
|
||||
|
||||
pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.tera");
|
||||
|
||||
#[derive(Debug, Clone, Args, Builder)]
|
||||
#[derive(Debug, Clone, Args, TypedBuilder)]
|
||||
pub struct TemplateCommand {
|
||||
/// The recipe file to create a template from
|
||||
#[arg()]
|
||||
|
|
@ -23,12 +23,12 @@ pub struct TemplateCommand {
|
|||
|
||||
/// Optional Containerfile to use as a template
|
||||
#[arg(short, long)]
|
||||
#[builder(default)]
|
||||
#[builder(default, setter(into))]
|
||||
containerfile: Option<PathBuf>,
|
||||
|
||||
/// File to output to instead of STDOUT
|
||||
#[arg(short, long)]
|
||||
#[builder(default)]
|
||||
#[builder(default, setter(into))]
|
||||
output: Option<PathBuf>,
|
||||
}
|
||||
|
||||
|
|
@ -72,10 +72,6 @@ impl TemplateCommand {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn builder() -> TemplateCommandBuilder {
|
||||
TemplateCommandBuilder::default()
|
||||
}
|
||||
|
||||
fn setup_tera(&self) -> Result<(Tera, Context)> {
|
||||
trace!("TemplateCommand::setup_tera()");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue