Skip to main content

cbor_cli/
config.rs

1use clap::{Parser, Subcommand};
2use std::path::PathBuf;
3
4#[derive(Parser)]
5#[command(author, version, about, long_about = None)]
6pub struct Cli {
7  /// Increase diagnostic output (repeatable: -v, -vv)
8  #[arg(short, long, action = clap::ArgAction::Count, global = true)]
9  pub verbose: u8,
10
11  /// Delimiter between output items. The escapes \n and \t are recognized.
12  #[arg(short, long, global = true)]
13  pub delimiter: Option<String>,
14
15  #[command(subcommand)]
16  pub command: Option<Commands>,
17}
18
19#[derive(Subcommand)]
20pub enum Commands {
21  /// Render CBOR in Concise Diagnostic Notation (RFC 8949 ยง8)
22  Inspect {
23    /// CBOR files to inspect. Reads from stdin if omitted.
24    #[arg(value_name = "INPUT_PATHS")]
25    input_paths: Vec<PathBuf>,
26  },
27
28  /// Encode JSON/YAML/TOML/CBOR files to CBOR
29  Import {
30    /// Input files. Reads from stdin if omitted.
31    #[arg(value_name = "INPUT_PATHS")]
32    input_paths: Vec<PathBuf>,
33
34    /// Format of the input. One of: json, yaml, toml, cbor.
35    ///
36    /// If omitted, inferred from each file's extension (json/yaml/toml).
37    /// Required when reading from stdin.
38    #[arg(long, value_name = "FORMAT")]
39    format: Option<String>,
40  },
41
42  /// Decode CBOR files to JSON/YAML/TOML/CBOR
43  Export {
44    /// CBOR input files. Reads from stdin if omitted.
45    #[arg(value_name = "INPUT_PATHS")]
46    input_paths: Vec<PathBuf>,
47
48    /// Format of the output. One of: json, yaml, toml, cbor.
49    #[arg(long, value_name = "FORMAT", default_value = "json")]
50    format: String,
51
52    /// Pretty-print JSON output with indentation (ignored for other formats).
53    #[arg(long)]
54    pretty: bool,
55  },
56}
57
58pub fn get_cli() -> Cli {
59  Cli::parse()
60}