rhd/src/main.rs

40 lines
798 B
Rust

use std::fs::File;
use std::io;
use std::usize::MAX;
mod colormap;
mod tohex;
use tohex::hexdump;
use clap::Parser;
#[derive(Parser)]
#[command(version, about = "A simple hexdump tool")]
struct Arguments {
/// Stop after <len> octets
#[arg(short, long)]
length: Option<usize>,
/// Filename to read, if left out read from stdin
filename: Option<String>,
}
fn main() {
let args = Arguments::parse();
let reader: Box<dyn io::Read> = if args.filename.is_none() {
Box::new(io::stdin())
} else {
let filename = args.filename.unwrap();
Box::new(File::open(filename).expect("Could not open file."))
};
let length = if args.length.is_some() {
args.length.unwrap()
} else {
MAX
};
hexdump(reader, length);
}