2023-09-24 13:51:35 +02:00
|
|
|
mod logging;
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use anyhow::anyhow;
|
2023-09-24 12:18:29 +02:00
|
|
|
use clap::{Args, Parser, Subcommand, ValueEnum};
|
2023-09-24 13:51:35 +02:00
|
|
|
use logging::LogArg;
|
2023-09-24 12:18:29 +02:00
|
|
|
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"
|
|
|
|
)]
|
2023-09-24 13:51:35 +02:00
|
|
|
crunch_file: PathBuf,
|
2023-09-24 12:18:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
2023-09-24 13:51:35 +02:00
|
|
|
async fn main() -> anyhow::Result<()> {
|
2023-09-24 12:18:29 +02:00
|
|
|
let cli = Cli::parse();
|
2023-09-24 13:51:35 +02:00
|
|
|
cli.global_args.log.init_logging();
|
2023-09-24 12:18:29 +02:00
|
|
|
|
|
|
|
match &cli.commands {
|
2023-09-24 13:51:35 +02:00
|
|
|
Commands::Generate {} => {
|
|
|
|
let config_file = config::get_file(&cli.global_args.crunch_file)
|
|
|
|
.await
|
|
|
|
.map_err(|e| anyhow!("failed to load config: {}", e))?
|
|
|
|
.get_config()
|
|
|
|
.map_err(|e| anyhow!("invalid config: {}", e))?;
|
|
|
|
|
|
|
|
tracing::info!("generating crunch code")
|
|
|
|
}
|
2023-09-24 12:18:29 +02:00
|
|
|
}
|
2023-09-24 13:51:35 +02:00
|
|
|
|
|
|
|
Ok(())
|
2023-09-24 12:18:29 +02:00
|
|
|
}
|
|
|
|
|
2023-09-24 13:51:35 +02:00
|
|
|
mod config {
|
|
|
|
pub async fn get_file(path: &std::path::Path) -> anyhow::Result<crunch_file::File> {
|
|
|
|
let file = crunch_file::File::parse_file(path).await?;
|
|
|
|
|
|
|
|
Ok(file)
|
2023-09-24 12:18:29 +02:00
|
|
|
}
|
|
|
|
}
|