generated from GarandPLG/rust-flake-template
init
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
use crate::logs::init_logger;
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
#[command(version, about = "Veil.rs", long_about = "Veil.rs")]
|
||||
pub struct Cli {
|
||||
#[arg(
|
||||
long,
|
||||
short = 'l',
|
||||
help = "Enable logging to file (default: disabled)",
|
||||
default_value_t = false
|
||||
)]
|
||||
pub log: bool,
|
||||
}
|
||||
|
||||
impl Cli {
|
||||
pub fn get_args() -> Self {
|
||||
let args: Cli = Cli::parse();
|
||||
|
||||
if args.log {
|
||||
init_logger();
|
||||
}
|
||||
|
||||
args
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod cli;
|
||||
pub mod logs;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
use simplelog::{Config, LevelFilter, WriteLogger};
|
||||
use std::fs::File;
|
||||
|
||||
pub fn init_logger() {
|
||||
WriteLogger::init(
|
||||
LevelFilter::Info,
|
||||
Config::default(),
|
||||
File::create("veil-rs.log").expect("Failed to create log file"),
|
||||
)
|
||||
.expect("Failed to initialize logger");
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
use veil_rs::cli::Cli;
|
||||
|
||||
fn main() {
|
||||
let args: Cli = Cli::get_args();
|
||||
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user