summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
blob: 42285e64b6e0274445d050254d4d064e66874ef8 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use clap::Parser;

#[allow(clippy::struct_excessive_bools, clippy::module_name_repetitions)]
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
    /// Choose a model
    #[clap(short, long)]
    pub model: Option<String>,
    /// Add a GPT prompt
    #[clap(short, long)]
    pub prompt: Option<String>,
    /// Disable syntax highlighting
    #[clap(short = 'H', long)]
    pub no_highlight: bool,
    /// No stream output
    #[clap(short = 'S', long)]
    pub no_stream: bool,
    /// List all roles
    #[clap(long)]
    pub list_roles: bool,
    /// List all models
    #[clap(long)]
    pub list_models: bool,
    /// Select a role
    #[clap(short, long)]
    pub role: Option<String>,
    /// Print system-wide information
    #[clap(long)]
    pub info: bool,
    /// Run in dry run mode
    #[clap(long)]
    pub dry_run: bool,
    /// Input text
    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)
    }
}