94 lines
2.4 KiB
Rust
94 lines
2.4 KiB
Rust
use anyhow::Result;
|
|
use clap::{Parser, Subcommand};
|
|
use libjrpc::{
|
|
targets::{
|
|
csharp::CSharpCompiler,
|
|
rust::RustCompiler,
|
|
typescript::{Node, TypeScriptCompiler},
|
|
},
|
|
FileProcessor,
|
|
};
|
|
|
|
#[cfg(test)]
|
|
mod test;
|
|
|
|
#[derive(Parser)]
|
|
struct Cli {
|
|
#[command(subcommand)]
|
|
command: Commands,
|
|
#[arg(short, long, global = true)]
|
|
verbose: bool,
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
enum Commands {
|
|
Compile {
|
|
input: String,
|
|
#[arg(short, long)]
|
|
output: String,
|
|
#[arg(short, long)]
|
|
definition: Option<String>,
|
|
},
|
|
Targets,
|
|
}
|
|
|
|
pub fn main() -> Result<()> {
|
|
use simple_logger::SimpleLogger;
|
|
SimpleLogger::new().init()?;
|
|
|
|
let cli = Cli::parse();
|
|
|
|
if cli.verbose {
|
|
log::set_max_level(log::LevelFilter::Trace);
|
|
} else {
|
|
log::set_max_level(log::LevelFilter::Warn);
|
|
}
|
|
|
|
match cli.command {
|
|
Commands::Compile {
|
|
input,
|
|
output,
|
|
definition,
|
|
} => {
|
|
let mut fp = FileProcessor::new();
|
|
let ir = fp.start_compile(&input)?;
|
|
|
|
let output_split = output.split(':').collect::<Vec<&str>>();
|
|
if output_split.len() != 2 {
|
|
println!("The output must follow the structure: <target:path>");
|
|
} else {
|
|
let output_target = output_split[0];
|
|
let output_dir = output_split[1];
|
|
|
|
match output_target {
|
|
"rust" => libjrpc::targets::compile::<RustCompiler>(ir, output_dir)?,
|
|
"ts-node" => {
|
|
libjrpc::targets::compile::<TypeScriptCompiler<Node>>(ir, output_dir)?
|
|
}
|
|
"ts-esm" => {
|
|
libjrpc::targets::compile::<TypeScriptCompiler<Node>>(ir, output_dir)?
|
|
}
|
|
"csharp" => libjrpc::targets::compile::<CSharpCompiler>(ir, output_dir)?,
|
|
_ => {
|
|
println!("Unsupported target: {}", output_target);
|
|
}
|
|
}
|
|
}
|
|
|
|
if let Some(_def) = definition {
|
|
panic!("Definition output is not yet implemented!");
|
|
}
|
|
|
|
//TODO: Implement definition output!
|
|
}
|
|
Commands::Targets => {
|
|
println!("rust");
|
|
println!("ts-node");
|
|
println!("ts-esm");
|
|
println!("csharp")
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|