generated from GarandPLG/rust-flake-template
Add subcommand support with colored help banner
Enable `clap` color feature, introduce subcommands (Sync, Add, Rm, Ls) and a custom before‑help banner, and update `main` to return a `Result`.
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
+36
-2
@@ -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()
|
||||
}
|
||||
|
||||
+3
-2
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user