quick_type_schema/
cli_builder.rs

1use super::*;
2
3#[derive(Debug, Clone)]
4pub struct CliBuilder {
5    args: Vec<String>,
6}
7
8impl CliBuilder {
9    pub fn new(lang: &Language) -> Self {
10        let args = vec!["-l".to_owned(), lang.name().to_owned()];
11        Self { args }
12    }
13
14    pub fn opt_bool(mut self, arg: &str, cond: bool) -> Self {
15        if cond {
16            self.args.push(arg.to_owned());
17        }
18        self
19    }
20
21    pub fn opt_string(mut self, arg: &str, opt: &str) -> Self {
22        if !opt.is_empty() {
23            self.args.push(arg.to_owned());
24            self.args.push(opt.to_owned());
25        }
26        self
27    }
28
29    pub fn opt_enum<E: Default + PartialEq, F: FnOnce() -> &'static str>(
30        mut self,
31        arg: &str,
32        opt: &E,
33        f: F,
34    ) -> Self {
35        if *opt != E::default() {
36            self.args.push(arg.to_owned());
37            self.args.push(f().to_owned());
38        }
39        self
40    }
41
42    pub fn build(self) -> Vec<String> {
43        self.args
44    }
45}