Enable CommandLine arguments
This commit is contained in:
parent
4c06001b48
commit
efc299fff1
|
@ -6,5 +6,6 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tool_helper = {path = "../tool_helper"}
|
clap = {version = "*", features = ["derive"]}
|
||||||
serde_json = "*"
|
serde_json = "*"
|
||||||
|
tool_helper = {path = "../tool_helper"}
|
|
@ -1,31 +1,40 @@
|
||||||
use mkoverlay::types::{OverlaySection, OverlaySlot};
|
use clap::Parser;
|
||||||
use tool_helper::{Error, open_input, open_output};
|
use tool_helper::{Error, format_if_error, open_input, open_output};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn _generate_file() -> Vec<OverlaySlot> {
|
#[derive(Parser)]
|
||||||
let mut slots = Vec::new();
|
#[clap(about = "Creates a linker script and makefile part for the JabyEngine toolchain", long_about = None)]
|
||||||
let mut slot = OverlaySlot::new("slot_0".to_owned(), None);
|
struct CommandLine {
|
||||||
let mut section = OverlaySection::new("main_area".to_owned());
|
#[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")]
|
||||||
slot.add_section(section);
|
ld_file_output: Option<PathBuf>,
|
||||||
slots.push(slot);
|
|
||||||
|
#[clap(value_parser, help="Input JSON for creating the files")]
|
||||||
slots
|
input: PathBuf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_main() -> Result<(), Error> {
|
fn run_main(cmd_line: CommandLine) -> Result<(), Error> {
|
||||||
let input = mkoverlay::types::json_reader::read_config(open_input(Some(PathBuf::from("../Tests/Overlay.json")))?)?;
|
let input = format_if_error!(open_input(Some(cmd_line.input)), "Opening input file failed with: {error_text}")?;
|
||||||
let mut output = open_output(None)?;
|
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)?;
|
format_if_error!(mkoverlay::creator::makefile::write(&mut mk_output, &input), "Writing makefile failed with: {error_text}")?;
|
||||||
mkoverlay::creator::ldscript::write(&mut output, &input)
|
format_if_error!(mkoverlay::creator::ldscript::write(&mut ld_output, &input), "Writing ld script failed with: {error_text}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match run_main() {
|
match CommandLine::try_parse() {
|
||||||
Ok(()) => println!("Planschbecken!!"),
|
Ok(cmd_line) => {
|
||||||
Err(error) => println!("{}", error),
|
match run_main(cmd_line) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(error) => println!("{}", error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(error) => {
|
||||||
|
println!("{}", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue