Skip to content

Commit

Permalink
Use bp3d-util to simplify bpxdump
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuri6037 committed Dec 5, 2024
1 parent ebd001d commit ef877ae
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 250 deletions.
140 changes: 36 additions & 104 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dump/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2018"
[dependencies]
clap = "2.27.0"
bpx = { version = "4.0.0-rc.10.0.1", features = ["sd", "sd-formatting"] }
bp3d-util = { version = "1.4.0", features = ["result", "simple-error"] }

[dev-dependencies]
assert_cmd = "1.0.4"
Expand Down
46 changes: 10 additions & 36 deletions dump/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,17 @@
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::fmt::{Display, Formatter};
use bp3d_util::simple_error;

use bpx::macros::impl_err_conversion;

pub enum Error
{
Bpx(bpx::core::error::Error),
Io(std::io::Error),
Sd(bpx::sd::error::Error),
TypeError(bpx::sd::error::TypeError),
Parsing(String),
SectionNotFound(u32),
BinaryOutput
}

impl_err_conversion!(
Error {
bpx::core::error::Error => Bpx,
std::io::Error => Io,
bpx::sd::error::Error => Sd,
bpx::sd::error::TypeError => TypeError
}
);

impl Display for Error
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result
{
match self {
Error::Bpx(e) => write!(f, "BPX error: {}", e),
Error::Io(e) => write!(f, "IO error: {}", e),
Error::Sd(e) => write!(f, "BPXSD error: {}", e),
Error::Parsing(s) => write!(f, "Could not parse value ({})", s),
Error::SectionNotFound(id) => write!(f, "Could not find section with index {}", id),
Error::BinaryOutput => f.write_str("Outputing binary data to standard output can mess-up your terminal, please use --force if you're sure to continue"),
Error::TypeError(e) => write!(f, "BPXSD type error: {}", e)
}
simple_error! {
pub Error {
(impl From) Bpx(bpx::core::error::Error) => "bpx error: {}",
(impl From) Io(std::io::Error) => "io error: {}",
(impl From) Sd(bpx::sd::error::Error) => "bpxsd error: {}",
(impl From) TypeError(bpx::sd::error::TypeError) => "bpxsd type error: {}",
(impl From) Parsing(String) => "could not parse value ({})",
(impl From) SectionNotFound(u32) => "could not find section with index {}",
(impl From) BinaryOutput => "outputing binary data to standard output can mess-up your terminal, please use --force if you're sure to continue"
}
}

Expand Down
12 changes: 3 additions & 9 deletions dump/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::path::Path;

use bp3d_util::result::ResultExt;
use clap::clap_app;

mod bpxinfo;
Expand All @@ -38,7 +38,7 @@ mod type_ext_maps;
fn main()
{
let matches = clap_app!(bpxdump =>
(version: "1.0")
(version: "2.0")
(author: "BlockProject3D <https://github.com/BlockProject3D>")
(about: "Dumps content of a given BPX file")
(@arg file: -f --file +required +takes_value "Path to the BPX file to debug")
Expand All @@ -56,11 +56,5 @@ fn main()
.get_matches();
let file = matches.value_of("file").unwrap();

match bpxinfo::run(Path::new(file), &matches) {
Ok(()) => std::process::exit(0),
Err(e) => {
eprintln!("{}", e);
std::process::exit(1)
}
}
bpxinfo::run(Path::new(file), &matches).expect_exit("bpxdump", 1);
}
Loading

0 comments on commit ef877ae

Please sign in to comment.