cbor-cli 0.7.0

Encode, decode, and inspect CBOR (RFC 8949) from the command line. Convert between CBOR, JSON, YAML, and TOML via serde, with streaming support for CBOR sequences.
Documentation
use clap::{Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
  /// Increase diagnostic output (repeatable: -v, -vv)
  #[arg(short, long, action = clap::ArgAction::Count, global = true)]
  pub verbose: u8,

  /// Delimiter between output items. The escapes \n and \t are recognized.
  #[arg(short, long, global = true)]
  pub delimiter: Option<String>,

  #[command(subcommand)]
  pub command: Option<Commands>,
}

#[derive(Subcommand)]
pub enum Commands {
  /// Render CBOR in Concise Diagnostic Notation (RFC 8949 ยง8)
  Inspect {
    /// CBOR files to inspect. Reads from stdin if omitted.
    #[arg(value_name = "INPUT_PATHS")]
    input_paths: Vec<PathBuf>,
  },

  /// Encode JSON/YAML/TOML/CBOR files to CBOR
  Import {
    /// Input files. Reads from stdin if omitted.
    #[arg(value_name = "INPUT_PATHS")]
    input_paths: Vec<PathBuf>,

    /// Format of the input. One of: json, yaml, toml, cbor.
    ///
    /// If omitted, inferred from each file's extension (json/yaml/toml).
    /// Required when reading from stdin.
    #[arg(long, value_name = "FORMAT")]
    format: Option<String>,
  },

  /// Decode CBOR files to JSON/YAML/TOML/CBOR
  Export {
    /// CBOR input files. Reads from stdin if omitted.
    #[arg(value_name = "INPUT_PATHS")]
    input_paths: Vec<PathBuf>,

    /// Format of the output. One of: json, yaml, toml, cbor.
    #[arg(long, value_name = "FORMAT", default_value = "json")]
    format: String,

    /// Pretty-print JSON output with indentation (ignored for other formats).
    #[arg(long)]
    pretty: bool,
  },
}

pub fn get_cli() -> Cli {
  Cli::parse()
}