27 lines
748 B
Rust
27 lines
748 B
Rust
use clap::Parser;
|
|
|
|
/// Clap is great! Even though we don't have many command line arguments
|
|
/// yet, this is just really neat.
|
|
#[derive(Parser, Debug)]
|
|
#[clap(author, version, about, long_about = None)]
|
|
struct CommandLineArguments {
|
|
/// Optional output file name
|
|
#[clap(short, long)]
|
|
output: Option<String>,
|
|
|
|
/// The file to parse
|
|
file: String,
|
|
}
|
|
|
|
fn main() {
|
|
let args = CommandLineArguments::parse();
|
|
let mut compiler = ngr::Compiler::default();
|
|
|
|
let output_file = args.output.unwrap_or("output.o".to_string());
|
|
|
|
if let Some(bytes) = compiler.compile(&args.file) {
|
|
std::fs::write(&output_file, bytes)
|
|
.unwrap_or_else(|x| eprintln!("Could not write to file {}: {}", output_file, x));
|
|
}
|
|
}
|