Skip to main content

commonmeta/cmd/
decode.rs

1/*
2 * Copyright © 2026 Front Matter <info@front-matter.de>
3 */
4
5use clap::{ArgMatches, Command};
6
7use crate::utils::decode_id;
8
9/// Build the decode subcommand
10pub fn command() -> Command {
11    Command::new("decode")
12        .about("Decode an identifier.")
13        .long_about(
14            "Decode a DOI, ROR or ORCID identifier. For DOIs only Crockford \
15            base32-encoding is supported, used by Rogue Scholar and some DataCite \
16            members.\n\n\
17            Example usage:\n\n\
18            commonmeta decode 10.54900/d3ck1-skq19",
19        )
20        .arg(
21            clap::Arg::new("identifier")
22                .help("Identifier to decode")
23                .required(true)
24                .index(1),
25        )
26}
27
28/// Execute the decode command
29pub fn execute(matches: &ArgMatches) -> Result<(), String> {
30    let input = matches.get_one::<String>("identifier").expect("required");
31
32    match decode_id(input) {
33        Ok(number) => {
34            println!("{}", number);
35            Ok(())
36        }
37        Err(e) => {
38            println!("{}", e);
39            Err(e)
40        }
41    }
42}