From 006966bb351a34c435726dd7e202790001005a7c Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Sat, 16 Dec 2023 20:41:36 -0500 Subject: [PATCH] fix: Move command structs into bin --- .helix/languages.toml | 5 ++--- src/bin/ublue.rs | 46 +++++++++++++++++++++++++++++++++++++++++-- src/lib.rs | 41 -------------------------------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/.helix/languages.toml b/.helix/languages.toml index 2d90176..d3b5352 100644 --- a/.helix/languages.toml +++ b/.helix/languages.toml @@ -1,3 +1,2 @@ -[[language]] -name = "rust" -# config = { cargo = { features = [ "modules" ], noDefaultFeatures = false } } +[language-server.rust-analyzer.config] +cargo.features = ["init"] diff --git a/src/bin/ublue.rs b/src/bin/ublue.rs index 42af249..c2f1e5b 100644 --- a/src/bin/ublue.rs +++ b/src/bin/ublue.rs @@ -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, + + /// File to output to instead of STDOUT + #[arg(short, long)] + output: Option, + }, + + /// 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, + }, + + /// Build an image from a Containerfile + #[cfg(feature = "build")] + Build { + #[arg()] + containerfile: String, + }, +} fn main() -> Result<()> { let args = UblueArgs::parse(); diff --git a/src/lib.rs b/src/lib.rs index 712f44d..f19d0a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, - - /// File to output to instead of STDOUT - #[arg(short, long)] - output: Option, - }, - - /// 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, - }, - - /// Build an image from a Containerfile - #[cfg(feature = "build")] - Build { - #[arg()] - containerfile: String, - }, -} - pub fn setup_tera(recipe: String, containerfile: Option) -> Result<(Tera, Context)> { let recipe_de = serde_yaml::from_str::(fs::read_to_string(PathBuf::from(&recipe))?.as_str())?;