fix: Move command structs into bin

This commit is contained in:
Gerald Pinder 2023-12-16 20:41:36 -05:00
parent 49d512b3f1
commit 006966bb35
3 changed files with 46 additions and 46 deletions

View file

@ -1,3 +1,2 @@
[[language]]
name = "rust"
# config = { cargo = { features = [ "modules" ], noDefaultFeatures = false } }
[language-server.rust-analyzer.config]
cargo.features = ["init"]

View file

@ -1,6 +1,48 @@
use std::path::PathBuf;
use anyhow::Result;
use clap::Parser;
use ublue_rs::{self, CommandArgs, UblueArgs};
use clap::{Parser, Subcommand};
use ublue_rs::{self};
#[derive(Parser, Debug)]
#[command(name = "Ublue Builder", author, version, about, long_about = None)]
struct UblueArgs {
#[command(subcommand)]
command: CommandArgs,
}
#[derive(Debug, Subcommand)]
enum CommandArgs {
/// Generate a Containerfile from a recipe
Template {
/// The recipe file to create a template from
#[arg()]
recipe: String,
/// Optional Containerfile to use as a template
#[arg(short, long)]
containerfile: Option<PathBuf>,
/// File to output to instead of STDOUT
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Initialize a new Ublue Starting Point repo
#[cfg(feature = "init")]
Init {
/// The directory to extract the files into. Defaults to the current directory
#[arg()]
dir: Option<PathBuf>,
},
/// Build an image from a Containerfile
#[cfg(feature = "build")]
Build {
#[arg()]
containerfile: String,
},
}
fn main() -> Result<()> {
let args = UblueArgs::parse();

View file

@ -28,7 +28,6 @@ use std::{
use anyhow::Result;
use cfg_if;
use clap::{Parser, Subcommand};
use tera::{Context, Tera};
cfg_if::cfg_if! {
@ -42,46 +41,6 @@ cfg_if::cfg_if! {
}
}
#[derive(Parser, Debug)]
#[command(name = "Ublue Builder", author, version, about, long_about = None)]
pub struct UblueArgs {
#[command(subcommand)]
pub command: CommandArgs,
}
#[derive(Debug, Subcommand)]
pub enum CommandArgs {
/// Generate a Containerfile from a recipe
Template {
/// The recipe file to create a template from
#[arg()]
recipe: String,
/// Optional Containerfile to use as a template
#[arg(short, long)]
containerfile: Option<PathBuf>,
/// File to output to instead of STDOUT
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Initialize a new Ublue Starting Point repo
#[cfg(feature = "init")]
Init {
/// The directory to extract the files into. Defaults to the current directory
#[arg()]
dir: Option<PathBuf>,
},
/// Build an image from a Containerfile
#[cfg(feature = "build")]
Build {
#[arg()]
containerfile: String,
},
}
pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Tera, Context)> {
let recipe_de =
serde_yaml::from_str::<Recipe>(fs::read_to_string(PathBuf::from(&recipe))?.as_str())?;