Enable CommandLine arguments

This commit is contained in:
Jaby 2022-12-04 03:13:48 +01:00
parent c6ec12d89f
commit bf0c5eea4c
2 changed files with 33 additions and 23 deletions

View File

@ -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 = "*"
clap = {version = "*", features = ["derive"]}
serde_json = "*"
tool_helper = {path = "../tool_helper"}

View File

@ -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<OverlaySlot> {
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<PathBuf>,
#[clap(long="ld-script", help="Output path for the linker script file")]
ld_file_output: Option<PathBuf>,
#[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);
}
}
}