diff --git a/src/Tools/mkoverlay/Cargo.toml b/src/Tools/mkoverlay/Cargo.toml index f9eea239..34c0e21d 100644 --- a/src/Tools/mkoverlay/Cargo.toml +++ b/src/Tools/mkoverlay/Cargo.toml @@ -6,5 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tool_helper = {path = "../tool_helper"} -serde_json = "*" \ No newline at end of file +clap = {version = "*", features = ["derive"]} +serde_json = "*" +tool_helper = {path = "../tool_helper"} \ No newline at end of file diff --git a/src/Tools/mkoverlay/src/main.rs b/src/Tools/mkoverlay/src/main.rs index 99d7dab0..dab87161 100644 --- a/src/Tools/mkoverlay/src/main.rs +++ b/src/Tools/mkoverlay/src/main.rs @@ -1,31 +1,40 @@ -use mkoverlay::types::{OverlaySection, OverlaySlot}; -use tool_helper::{Error, open_input, open_output}; +use clap::Parser; +use tool_helper::{Error, format_if_error, open_input, open_output}; use std::path::PathBuf; -fn _generate_file() -> Vec { - let mut slots = Vec::new(); - let mut slot = OverlaySlot::new("slot_0".to_owned(), None); - let mut section = OverlaySection::new("main_area".to_owned()); - - section.add_file_pattern("bin/PSX-release/src/*.o".to_owned()); - - slot.add_section(section); - slots.push(slot); - - slots +#[derive(Parser)] +#[clap(about = "Creates a linker script and makefile part for the JabyEngine toolchain", long_about = None)] +struct CommandLine { + #[clap(long="mk-file", help="Output path for the makefile")] + mk_file_output: Option, + + #[clap(long="ld-script", help="Output path for the linker script file")] + ld_file_output: Option, + + #[clap(value_parser, help="Input JSON for creating the files")] + input: PathBuf } -fn run_main() -> Result<(), Error> { - let input = mkoverlay::types::json_reader::read_config(open_input(Some(PathBuf::from("../Tests/Overlay.json")))?)?; - let mut output = open_output(None)?; +fn run_main(cmd_line: CommandLine) -> Result<(), Error> { + let input = format_if_error!(open_input(Some(cmd_line.input)), "Opening input file failed with: {error_text}")?; + let input = format_if_error!(mkoverlay::types::json_reader::read_config(input), "Parsing JSON file failed with: {error_text}")?; + let mut mk_output = format_if_error!(open_output(cmd_line.mk_file_output), "Opening file for writing makefile failed with: {error_text}")?; + let mut ld_output = format_if_error!(open_output(cmd_line.ld_file_output), "Opening file for writing linkerfile failed with: {error_text}")?; - mkoverlay::creator::makefile::write(&mut output, &input)?; - mkoverlay::creator::ldscript::write(&mut output, &input) + format_if_error!(mkoverlay::creator::makefile::write(&mut mk_output, &input), "Writing makefile failed with: {error_text}")?; + format_if_error!(mkoverlay::creator::ldscript::write(&mut ld_output, &input), "Writing ld script failed with: {error_text}") } fn main() { - match run_main() { - Ok(()) => println!("Planschbecken!!"), - Err(error) => println!("{}", error), + match CommandLine::try_parse() { + Ok(cmd_line) => { + match run_main(cmd_line) { + Ok(_) => (), + Err(error) => println!("{}", error) + } + }, + Err(error) => { + println!("{}", error); + } } } \ No newline at end of file