feat: with crunch file support
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
15
crates/crunch-cli/Cargo.toml
Normal file
15
crates/crunch-cli/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "crunch-cli"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
tracing.workspace = true
|
||||
tokio.workspace = true
|
||||
thiserror.workspace = true
|
||||
async-trait.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
clap.workspace = true
|
78
crates/crunch-cli/src/main.rs
Normal file
78
crates/crunch-cli/src/main.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
use clap::{Args, Parser, Subcommand, ValueEnum};
|
||||
use tracing::Level;
|
||||
|
||||
#[derive(Parser, Clone)]
|
||||
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
commands: Commands,
|
||||
|
||||
#[command(flatten)]
|
||||
global_args: GlobalArgs,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Clone)]
|
||||
enum Commands {
|
||||
Generate {},
|
||||
}
|
||||
|
||||
#[derive(Args, Clone)]
|
||||
struct GlobalArgs {
|
||||
#[arg(long, default_value = "none", global = true, help_heading = "Global")]
|
||||
log: LogArg,
|
||||
|
||||
#[arg(
|
||||
long,
|
||||
default_value = ".crunch.toml",
|
||||
global = true,
|
||||
help_heading = "Global"
|
||||
)]
|
||||
crunch_file: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, ValueEnum)]
|
||||
enum LogArg {
|
||||
None,
|
||||
Trace,
|
||||
Debug,
|
||||
Info,
|
||||
Warn,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let cli = Cli::parse();
|
||||
init_logging(&cli.global_args.log);
|
||||
|
||||
match &cli.commands {
|
||||
Commands::Generate {} => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn init_logging(log: &LogArg) {
|
||||
match log {
|
||||
LogArg::None => {}
|
||||
LogArg::Trace => {
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(Level::TRACE)
|
||||
.init();
|
||||
}
|
||||
LogArg::Debug => {
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(Level::DEBUG)
|
||||
.init();
|
||||
}
|
||||
LogArg::Info => {
|
||||
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
|
||||
}
|
||||
LogArg::Warn => {
|
||||
tracing_subscriber::fmt().with_max_level(Level::WARN).init();
|
||||
}
|
||||
LogArg::Error => {
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(Level::ERROR)
|
||||
.init();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user