fix: Move command structs into bin
This commit is contained in:
parent
49d512b3f1
commit
006966bb35
3 changed files with 46 additions and 46 deletions
|
|
@ -1,3 +1,2 @@
|
||||||
[[language]]
|
[language-server.rust-analyzer.config]
|
||||||
name = "rust"
|
cargo.features = ["init"]
|
||||||
# config = { cargo = { features = [ "modules" ], noDefaultFeatures = false } }
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,48 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::{Parser, Subcommand};
|
||||||
use ublue_rs::{self, CommandArgs, UblueArgs};
|
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<()> {
|
fn main() -> Result<()> {
|
||||||
let args = UblueArgs::parse();
|
let args = UblueArgs::parse();
|
||||||
|
|
|
||||||
41
src/lib.rs
41
src/lib.rs
|
|
@ -28,7 +28,6 @@ use std::{
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cfg_if;
|
use cfg_if;
|
||||||
use clap::{Parser, Subcommand};
|
|
||||||
use tera::{Context, Tera};
|
use tera::{Context, Tera};
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
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)> {
|
pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Tera, Context)> {
|
||||||
let recipe_de =
|
let recipe_de =
|
||||||
serde_yaml::from_str::<Recipe>(fs::read_to_string(PathBuf::from(&recipe))?.as_str())?;
|
serde_yaml::from_str::<Recipe>(fs::read_to_string(PathBuf::from(&recipe))?.as_str())?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue