lib_wpsr/
cli.rs

1use std::fmt::Display;
2
3use clap::{Parser, Subcommand};
4use clap_verbosity_flag::Verbosity;
5
6mod alpha;
7mod anagram;
8mod boxed;
9mod list;
10mod words;
11
12#[derive(Parser, Debug)]
13#[clap(author, version, about, long_about = None)]
14pub struct Cli {
15    /// logging level
16    #[clap(flatten)]
17    pub logging: Verbosity,
18    /// Commands to run
19    #[command(subcommand)]
20    pub cmd: Commands,
21}
22
23#[derive(Debug, Subcommand, Clone)]
24pub enum Commands {
25    /// Parse list of words to exclude duplicates and non-alphabetic characters
26    Alpha(alpha::Cmd),
27    /// List available word lists
28    List(list::Cmd),
29    /// Find words that are anagrams of a given letter string
30    Anagram(anagram::Cmd),
31    /// Boxed word puzzle tools
32    Boxed(boxed::Cmd),
33    /// Generate words from a string of letters
34    Words(words::Cmd),
35}
36
37impl Display for Commands {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        match self {
40            Commands::Alpha(_) => write!(f, "alpha"),
41            Commands::List(_) => write!(f, "list"),
42            Commands::Anagram(_) => write!(f, "anagram"),
43            Commands::Boxed(_) => write!(f, "boxed"),
44            Commands::Words(_) => write!(f, "words"),
45        }
46    }
47}