generated from GarandPLG/rust-flake-template
c78ce27dba
Enable `clap` color feature, introduce subcommands (Sync, Add, Rm, Ls) and a custom before‑help banner, and update `main` to return a `Result`.
61 lines
1.2 KiB
Rust
61 lines
1.2 KiB
Rust
use crate::logs::init_logger;
|
|
use clap::{Parser, Subcommand, builder::StyledStr};
|
|
|
|
#[derive(Parser, Debug, Clone)]
|
|
#[command(
|
|
version,
|
|
before_help = before_help(),
|
|
subcommand_required = false
|
|
)]
|
|
pub struct Cli {
|
|
#[arg(
|
|
long,
|
|
short = 'l',
|
|
help = "Enable logging to file (default: disabled)",
|
|
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 {
|
|
pub fn get_args() -> Self {
|
|
let args: Cli = Cli::parse();
|
|
|
|
if args.log {
|
|
init_logger();
|
|
}
|
|
|
|
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()
|
|
}
|