Skip to main content

bunsen_tool/text/text_command_group/
mod.rs

1//! `bunsen-tool text`: the command group.
2
3mod text_normalize;
4mod text_normalizers;
5
6use bunsen::errors::BunsenResult;
7pub use text_normalize::*;
8pub use text_normalizers::*;
9
10/// `bunsen-tool text`'s commands: text normalization on its own. `text
11/// normalize` runs normalizers over a text; `text normalizers` lists them.
12#[derive(clap::Args, Debug)]
13pub struct TextCommandGroup {
14    #[clap(subcommand)]
15    command: TextSubCommand,
16}
17
18#[derive(clap::Subcommand, Debug)]
19pub enum TextSubCommand {
20    /// Normalizes a text: numbers spoken, Unicode folded, punctuation dropped.
21    ///
22    /// The text, from the arguments, a file or stdin, through each
23    /// `--normalize` in order, to stdout; `--explain` shows each stage's
24    /// output.
25    Normalize(TextNormalizeCommand),
26
27    /// The normalizers `--normalize` names, and whether this build has each.
28    Normalizers(TextNormalizersCommand),
29}
30
31impl TextCommandGroup {
32    /// Runs the command.
33    pub fn run(&self) -> BunsenResult<()> {
34        match &self.command {
35            TextSubCommand::Normalize(cmd) => cmd.run(),
36            TextSubCommand::Normalizers(cmd) => cmd.run(),
37        }
38    }
39}