ldpc_toolbox/
cli.rs

1//! `ldpc-toolbox` CLI application
2//!
3//! The CLI application is organized in several subcommands. The
4//! supported subcommands can be seen by running `ldpc-toolbox`.
5//! See the modules below for examples and more information about
6//! how to use each subcommand.
7
8use clap::Parser;
9use std::error::Error;
10
11pub mod ber;
12pub mod ccsds;
13pub mod ccsds_c2;
14pub mod dvbs2;
15pub mod encode;
16pub mod mackay_neal;
17pub mod nr5g;
18pub mod peg;
19pub mod systematic;
20
21/// Trait to run a CLI subcommand
22pub trait Run {
23    /// Run the CLI subcommand
24    fn run(&self) -> Result<(), Box<dyn Error>>;
25}
26
27/// CLI arguments.
28#[derive(Debug, Parser)]
29#[command(author, version, name = "ldpc-toolbox", about = "LDPC toolbox")]
30pub enum Args {
31    /// Generates the alist of 5G NR LDPC codes.
32    #[command(name = "5g")]
33    NR5G(nr5g::Args),
34    /// ber subcommand
35    BER(ber::Args),
36    /// ccsds subcommand
37    CCSDS(ccsds::Args),
38    /// ccsds-c2 subcommand
39    #[allow(non_camel_case_types)]
40    CCSDS_C2(ccsds_c2::Args),
41    /// encode subcommand
42    Encode(encode::Args),
43    /// dvbs2 subcommand
44    DVBS2(dvbs2::Args),
45    /// mackay-neal subcommand
46    MackayNeal(mackay_neal::Args),
47    /// peg subcommand
48    PEG(peg::Args),
49    /// systematic subcommand
50    Systematic(systematic::Args),
51}
52
53impl Run for Args {
54    fn run(&self) -> Result<(), Box<dyn Error>> {
55        match self {
56            Args::BER(x) => x.run(),
57            Args::CCSDS(x) => x.run(),
58            Args::CCSDS_C2(x) => x.run(),
59            Args::DVBS2(x) => x.run(),
60            Args::Encode(x) => x.run(),
61            Args::MackayNeal(x) => x.run(),
62            Args::NR5G(x) => x.run(),
63            Args::PEG(x) => x.run(),
64            Args::Systematic(x) => x.run(),
65        }
66    }
67}