rhd/src/main.rs

42 lines
831 B
Rust

use std::fs::File;
use std::io;
mod colormap;
mod tohex;
use tohex::hexdump;
mod tobin;
use tobin::bindump;
use clap::Parser;
#[derive(Parser)]
#[command(version, about="A simple hexdump tool")]
struct Arguments {
/// Revert a hexdump to binary
#[arg(short, long)]
revert: bool,
/// 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."))
};
if !args.revert {
hexdump(reader);
} else {
let writer: Box<dyn io::Write> = Box::new(io::stdout());
bindump(reader, writer);
}
}