Enable CommandLine arguments
This commit is contained in:
parent
053fd6b738
commit
d61bf7b95c
|
@ -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"}
|
||||
clap = {version = "*", features = ["derive"]}
|
||||
serde_json = "*"
|
||||
tool_helper = {path = "../tool_helper"}
|
|
@ -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());
|
||||
#[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>,
|
||||
|
||||
section.add_file_pattern("bin/PSX-release/src/*.o".to_owned());
|
||||
#[clap(long="ld-script", help="Output path for the linker script file")]
|
||||
ld_file_output: Option<PathBuf>,
|
||||
|
||||
slot.add_section(section);
|
||||
slots.push(slot);
|
||||
|
||||
slots
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue