From 5aec230fcd72f886f5aaa3333ac1e279f5010624 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 10 Jan 2025 22:26:26 +0100 Subject: readrom: Remove the derive feature from clap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to statically build the 'readrom' binary, as that feature from clap prevented that option. Signed-off-by: Miquel Sabaté Solà --- crates/readrom/Cargo.toml | 2 +- crates/readrom/src/main.rs | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'crates') diff --git a/crates/readrom/Cargo.toml b/crates/readrom/Cargo.toml index 68ca68c..93d6134 100644 --- a/crates/readrom/Cargo.toml +++ b/crates/readrom/Cargo.toml @@ -7,5 +7,5 @@ license.workspace = true authors.workspace = true [dependencies] -clap = { version = "^4", features = ["derive"] } +clap = "^4" header.workspace = true diff --git a/crates/readrom/src/main.rs b/crates/readrom/src/main.rs index 32e648b..b43ccca 100644 --- a/crates/readrom/src/main.rs +++ b/crates/readrom/src/main.rs @@ -1,16 +1,8 @@ -use clap::Parser as ClapParser; +use clap::{Arg, Command}; use header::{Header, Kind}; use std::fs::File; use std::io::{ErrorKind, Read}; -/// Display information about NES/Famicom ROM files. -#[derive(ClapParser, Debug)] -#[command(version, about, long_about = None)] -struct Args { - /// NES/Famicom ROM file from which to display information. - file: String, -} - fn print_header(header: &Header) { println!("Header:"); @@ -34,14 +26,26 @@ fn print_header(header: &Header) { // Print the given `message` and exit(1). fn die(message: String) { - println!("{}", message); + println!("error: {}", message); std::process::exit(1); } fn main() { - let args = Args::parse(); - let Ok(mut input) = File::open(&args.file) else { - die(format!("failed to open the given file '{}'", &args.file)); + let args = Command::new("readrom") + .version("0.1.0") + .about("Display information about NES/Famicom ROM files.") + .arg(Arg::new("FILE").required(true).help("ROM file to be read")) + .get_matches(); + let file = match args.get_one::("FILE") { + Some(file) => file, + None => { + die("you have to provide a file".to_string()); + return; + } + }; + + let Ok(mut input) = File::open(file) else { + die(format!("failed to open the given file '{}'", &file)); return; }; -- cgit v1.2.3