summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
blob: 5d709eabe80174ef3db8aabcca302c58f13d2cae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
    /// List all roles
    #[clap(short = 'L', long)]
    pub list_roles: bool,
    /// Select a role
    #[clap(short, long)]
    pub role: Option<String>,
    /// Turn off highlight
    #[clap(short = 'H', long)]
    pub no_highlight: bool,
    /// Input text, if no input text, enter interactive mode
    text: Vec<String>,
}

impl Cli {
    pub fn text(&self) -> Option<String> {
        let text = self
            .text
            .iter()
            .map(|x| x.trim().to_string())
            .collect::<Vec<String>>()
            .join(" ");
        if text.is_empty() {
            return None;
        }
        Some(text)
    }
}