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
use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct ClientCli {
    #[clap(short = 'a', long, env = "ADDRESS", default_value = "http://127.0.0.1")]
    pub address: String,
    #[clap(short = 'p', long, env = "PORT", default_value = "8080")]
    pub port: String,
    #[clap(short = 'k', long, env = "KEY")]
    pub key: Option<String>,
    #[clap(trailing_var_arg = true)]
    text: Vec<String>,
}

impl ClientCli {
    pub fn endpoint(&self) -> String {
        format!("{}:{}", &self.address, &self.port)
    }

    pub fn text(&self) -> String {
        let text = self.text.iter().map(|x| x.trim()
            .to_string()).collect::<Vec<String>>().join(" ");
        text
    }
}