From e228e00a628175811392f134c31e83770534a533 Mon Sep 17 00:00:00 2001 From: Krusty/Benediction Date: Thu, 29 Feb 2024 15:46:37 +0100 Subject: [PATCH] embed all tools inside bndbuild. This aims to be the single file to share --- cpclib-bndbuild/src/main.rs | 28 +++++++++++++++++++++++++--- cpclib-bndbuild/src/runners/disc.rs | 2 +- cpclib-disc/src/lib.rs | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cpclib-bndbuild/src/main.rs b/cpclib-bndbuild/src/main.rs index 7566076b..f18ca4f4 100644 --- a/cpclib-bndbuild/src/main.rs +++ b/cpclib-bndbuild/src/main.rs @@ -16,17 +16,21 @@ fn main() { } fn inner_main() -> Result<(), BndBuilderError> { - let basm_command = cpclib_basm::build_args_parser().name("basm"); + let basm_cmd = cpclib_basm::build_args_parser().name("basm"); + let img2cpc_cmd = cpclib_imgconverter::build_args_parser().name("img2cpc"); + let xfer_cmd = cpclib_xfertool::build_args_parser().name("xfer"); + let disc_cmd = cpclib_disc::dsk_manager_build_arg_parser().name("disc"); let cmd = Command::new("bndbuilder") .about("Benediction CPC demo project builder") + .before_help("Can be used as a project builder similar to Make, but using a yaml project description, or can be used as any benedicition crossdev tool (basm, img2cpc, xfer, disc). This way only bndbuild needs to be installed.") .author("Krusty/Benediction") .version(built_info::PKG_VERSION) .disable_help_flag(true) .disable_version_flag(true) .subcommand_negates_reqs(true) .subcommand_precedence_over_arg(true) - .subcommand(basm_command) + .subcommands(&[basm_cmd, img2cpc_cmd.clone(), xfer_cmd, disc_cmd]) .arg( Arg::new("help") .long("help") @@ -91,7 +95,7 @@ fn inner_main() -> Result<(), BndBuilderError> { ) .arg( Arg::new("kind") - .help("The kind of command") + .help("The kind of command to be added in the yaml file") .long("kind") .short('k') .value_parser(["basm", "img2cpc", "xfer"]) @@ -129,6 +133,24 @@ fn inner_main() -> Result<(), BndBuilderError> { } } } + else if let Some(img2cpc) = matches.subcommand_matches("img2cpc") { + eprintln!("Switch to img2cpc behavior, not bndbuild one."); + cpclib_imgconverter::process(img2cpc, img2cpc_cmd) + .map_err(|e| e.to_string()) + .expect("Error when launching img2cpc tool"); + } + else if let Some(xfer) = matches.subcommand_matches("xfer") { + eprintln!("Switch to xfer behavior, not bndbuild one."); + cpclib_xfertool::process(xfer) + .map_err(|e| e.to_string()) + .expect("Error when launching xfer tool"); + } + else if let Some(disc) = matches.subcommand_matches("disc") { + eprintln!("Switch to disc behavior, not bndbuild one."); + cpclib_disc::dsk_manager_handle(disc) + .map_err(|e| e.to_string()) + .expect("Error when launching disc tool"); + } else { // handle the real behavior of bndbuild if matches.value_source("help") == Some(parser::ValueSource::CommandLine) { diff --git a/cpclib-bndbuild/src/runners/disc.rs b/cpclib-bndbuild/src/runners/disc.rs index b9d8bd2c..7e4521cb 100644 --- a/cpclib-bndbuild/src/runners/disc.rs +++ b/cpclib-bndbuild/src/runners/disc.rs @@ -31,7 +31,7 @@ impl RunnerWithClap for DiscManagerRunner { impl Runner for DiscManagerRunner { fn inner_run(&self, itr: &[String]) -> Result<(), String> { let matches = self.get_matches(itr)?; - cpclib_disc::dsk_manager_handle(matches).map_err(|e| e.to_string()) + cpclib_disc::dsk_manager_handle(&matches).map_err(|e| e.to_string()) } fn get_command(&self) -> &str { diff --git a/cpclib-disc/src/lib.rs b/cpclib-disc/src/lib.rs index 11926c1f..ef6abdbc 100644 --- a/cpclib-disc/src/lib.rs +++ b/cpclib-disc/src/lib.rs @@ -112,7 +112,7 @@ pub fn open_disc>( } #[cfg(feature = "cmdline")] -pub fn dsk_manager_handle(matches: ArgMatches) -> Result<(), DskManagerError> { +pub fn dsk_manager_handle(matches: &ArgMatches) -> Result<(), DskManagerError> {