tinycbor 0.12.1

A tiny CBOR codec library.
Documentation
use std::env;
use std::fs;
use std::io::{self, Read};
use std::process;

const SUMMARY: &str = r#"Usage: cbor-display OPTION*

With no OPTION or if OPTION is -, input is read from stdin.

  -f | --file PATH  Display contents of the file at PATH.
  -h | --help       Show this help message."#;

fn main() {
    let mut args = env::args().skip(1);

    match args.next().as_deref() {
        Some("-f") | Some("--file") => {
            if let Some(p) = args.next() {
                match fs::read(&p) {
                    Ok(f) => println!("{}", tinycbor::Decoder(&f)),
                    Err(e) => {
                        eprintln!("Failed to read \"{p}\": {e}.");
                        process::exit(2)
                    }
                }
            } else {
                eprintln!("-f | --file requires a path as argument.");
                process::exit(1)
            }
        }
        Some("-") | None => {
            let mut v = Vec::new();
            match io::stdin().read_to_end(&mut v) {
                Ok(_) => println!("{}", tinycbor::Decoder(&v)),
                Err(e) => {
                    eprintln!("Failed to read from stdin: {e}.");
                    process::exit(3)
                }
            }
        }
        Some("-h") | Some("--help") => {
            println!("{SUMMARY}")
        }
        Some(unknown) => {
            eprintln!("Unknown option: {unknown}\n\n{SUMMARY}");
            process::exit(1)
        }
    }
}