diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-10 22:26:26 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-10 22:29:46 +0100 |
| commit | 5aec230fcd72f886f5aaa3333ac1e279f5010624 (patch) | |
| tree | 8bc831d9e497337e125e9bea5972d1a91dd6ecc1 /crates/readrom/src/main.rs | |
| parent | 23b4fcf9bc5933c0370f74b61a6c2db2d4a0ac78 (diff) | |
| download | tools.nes-5aec230fcd72f886f5aaa3333ac1e279f5010624.tar.gz tools.nes-5aec230fcd72f886f5aaa3333ac1e279f5010624.zip | |
readrom: Remove the derive feature from clap
This allows us to statically build the 'readrom' binary, as that feature
from clap prevented that option.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'crates/readrom/src/main.rs')
| -rw-r--r-- | crates/readrom/src/main.rs | 30 |
1 files changed, 17 insertions, 13 deletions
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::<String>("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; }; |
