From c78ce27dbae573433af8afa5633e452960e2bae6 Mon Sep 17 00:00:00 2001 From: GarandPLG Date: Wed, 3 Jun 2026 16:35:31 +0200 Subject: [PATCH] Add subcommand support with colored help banner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable `clap` color feature, introduce subcommands (Sync, Add, Rm, Ls) and a custom before‑help banner, and update `main` to return a `Result`. --- Cargo.toml | 2 +- src/cli.rs | 38 ++++++++++++++++++++++++++++++++++++-- src/main.rs | 5 +++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8e64036..916a46f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ opt-level = 3 strip = true [dependencies] -clap = { version = "4.6.1", features = ["derive"] } +clap = { version = "4.6.1", features = ["derive", "color"] } serde = { version = "1.0.228", features = ["derive"] } serde_yaml = "0.9.33" dirs = "6.0.0" # XDG paths cross-platform diff --git a/src/cli.rs b/src/cli.rs index 21910e0..5de556c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,8 +1,12 @@ use crate::logs::init_logger; -use clap::Parser; +use clap::{Parser, Subcommand, builder::StyledStr}; #[derive(Parser, Debug, Clone)] -#[command(version, about = "Veil.rs", long_about = "Veil.rs")] +#[command( + version, + before_help = before_help(), + subcommand_required = false +)] pub struct Cli { #[arg( long, @@ -11,6 +15,17 @@ pub struct Cli { default_value_t = false )] pub log: bool, + + #[command(subcommand)] + pub command: Cmds, +} + +#[derive(Subcommand, Clone, Debug)] +pub enum Cmds { + Sync, + Add, + Rm, + Ls, } impl Cli { @@ -24,3 +39,22 @@ impl Cli { args } } + +fn before_help() -> StyledStr { + const BANNER: &str = r#" + ____ ____ .__.__ + \ \ / /____ |__| | _______ ______ + \ Y // __ \| | | \_ __ \/ ___/ + \ /\ ___/| | |__ | | \/\___ \ + \___/ \___ >__|____/ /\ |__| /____ > + \/ \/ \/ + "#; + + format!( + "{}\n{}\t\t{}", + BANNER, + "Declarative Tauri wrapper", + format!("v{}", env!("CARGO_PKG_VERSION")) + ) + .into() +} diff --git a/src/main.rs b/src/main.rs index 3f49780..4548382 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,8 @@ +use std::io::Result; use veil_rs::cli::Cli; -fn main() { +fn main() -> Result<()> { let args: Cli = Cli::get_args(); - println!("Hello, world!"); + Ok(()) }