glossa_cli/
options.rs

1use std::path::PathBuf;
2
3use clap::{ColorChoice, Parser};
4use getset::Getters;
5use glossa::MiniStr;
6use glossa_codegen::{Visibility, generator::MapType};
7
8use crate::{context::get_text, envs::format_glossa_env};
9
10#[derive(Parser, Debug, Getters, Clone)]
11#[getset(get = "pub with_prefix")]
12#[command(version)]
13#[command(arg_required_else_help = true)]
14#[command(color = ColorChoice::Always)]
15#[command(long_about = format_glossa_env())]
16pub struct Cli {
17  #[command(flatten)]
18  resources: Box<ResourcesOpt>,
19
20  #[command(flatten)]
21  generator: Box<GeneratorOpt>,
22
23  #[command(flatten)]
24  highlight: Box<HighlightOpt>,
25
26  #[command(flatten)]
27  dbg_options: DbgOpt,
28
29  #[arg(
30    long,
31    value_name = "regular|highlight|dsl|_",
32    default_value = "regular"
33  )]
34  map_type: MapType,
35}
36
37#[derive(Parser, Debug, Getters, Clone)]
38#[getset(get = "pub with_prefix")]
39pub struct DbgOpt {
40  #[arg(
41    long,
42    help_heading = "Debug",
43    help = get_text("display_config_dir", None),
44  )]
45  display_config_dir: bool,
46}
47
48#[derive(Parser, Debug, Getters, Clone)]
49#[getset(get = "pub with_prefix")]
50pub struct GeneratorOpt {
51  #[arg(
52    long,
53    value_hint = clap::ValueHint::DirPath,
54    help_heading = "Generator Core",
55    value_name = "/path/to/output_dir",
56    // long_help = get_args_md(b"outdir"),
57    help = get_text("outdir", None),
58  )]
59  outdir: Option<PathBuf>,
60
61  #[arg(
62    long,
63    visible_alias = "vis",
64    value_name = "pub| pub(crate)| pub(super)| private",
65    help_heading = "Generator Core",
66    help = get_text("visibility", None),
67  )]
68  visibility: Option<Visibility>,
69
70  #[arg(long, value_name = "string",
71    help_heading = "Generator Core",
72    help = get_text("bincode_suffix", None),
73  )]
74  bincode_suffix: Option<MiniStr>,
75
76  #[arg(long, value_name = "string",
77  help_heading = "Generator Core",
78  help = get_text("mod_prefix", None),
79  )]
80  mod_prefix: Option<MiniStr>,
81
82  // -------
83  #[arg(long, help_heading = "Output Files",
84    help = get_text("output_bincode", None),
85  )]
86  output_bincode: bool,
87
88  #[arg(long, help_heading = "Output File",
89    help = get_text("output_bincode_all_in_one", None),
90  )]
91  output_bincode_all_in_one: bool,
92
93  #[arg(long, help_heading = "Output Files", group = "output_map_fn",
94    help = get_text("output_match_fn", None),
95  )]
96  output_match_fn: bool,
97
98  #[arg(long, help_heading = "Output Files", group = "output_map_fn",
99    help = get_text("output_match_fn_without_map_name", None),
100  )]
101  output_match_fn_without_map_name: bool,
102
103  #[arg(long, help_heading = "Output File",
104    help = get_text("output_match_fn_all_in_one", None),
105  )]
106  output_match_fn_all_in_one: bool,
107
108  #[arg(long, help_heading = "Output File",
109    help = get_text("output_match_fn_all_in_one_by_language", None),
110  )]
111  output_match_fn_all_in_one_by_language: bool,
112
113  #[arg(long, help_heading = "Output File",
114    help = get_text("output_match_fn_all_in_one_without_map_name", None),
115  )]
116  output_match_fn_all_in_one_without_map_name: bool,
117
118  #[arg(long, help_heading = "Output Files", group = "output_map_fn",
119    help = get_text("output_phf", None),
120  )]
121  output_phf: bool,
122
123  #[arg(long, help_heading = "Output Files", group = "output_map_fn",
124    help = get_text("output_phf_without_map_name", None),
125  )]
126  output_phf_without_map_name: bool,
127
128  #[arg(long, help_heading = "Output File",
129    help = get_text("output_phf_all_in_one", None),
130  )]
131  output_phf_all_in_one: bool,
132
133  #[arg(long, help_heading = "Output String",
134    help = get_text("output_ron", None),
135  )]
136  output_ron: bool,
137
138  #[arg(long, help_heading = "Output String",
139    help = get_text("output_locales_fn", None),
140  )]
141  output_locales_fn: bool,
142
143  #[arg(long, help_heading = "Output String")]
144  output_raw_locales: bool,
145
146  #[arg(long, help_heading = "Output String")]
147  output_mod_rs: bool,
148
149  #[arg(long, help_heading = "Output String")]
150  output_cargo_features: bool,
151
152  #[arg(long, help_heading = "Output String")]
153  output_router_for_match_fns: bool,
154
155  #[arg(long, help_heading = "Output String")]
156  output_router_for_match_fns_without_map_name: bool,
157
158  #[arg(long, help_heading = "Output String")]
159  output_router_for_phf_maps: bool,
160
161  #[arg(long, help_heading = "Output String")]
162  output_router_for_phf_maps_without_map_name: bool,
163}
164
165#[derive(Parser, Debug, Getters, Clone)]
166#[getset(get = "pub with_prefix")]
167pub struct ResourcesOpt {
168  #[arg(
169    long,
170    help_heading = "L10nResources",
171    value_name = "/path/to/L10nDir",
172    default_value = "locales",
173    help = get_text("input", None),
174  )]
175  input: PathBuf,
176
177  #[arg(long, help_heading = "L10nResources", value_name = "string",
178    help = get_text("dsl_suffix", None),
179  )]
180  dsl_suffix: Option<MiniStr>,
181
182  #[arg(
183    long,
184    help_heading = "L10nResources",
185    value_name = "en,zh,fr,ru,ar,es,etc.",
186    value_delimiter = ',',
187    help = get_text("include_languages", None),
188  )]
189  include_languages: Vec<MiniStr>,
190
191  #[arg(
192    long,
193    help_heading = "L10nResources",
194    value_name = "name1,name2,..",
195    value_delimiter = ',',
196    help = get_text("include_map_names", None),
197  )]
198  include_map_names: Vec<MiniStr>,
199
200  #[arg(
201    long,
202    help_heading = "L10nResources",
203    value_name = "lang1,lang2,..",
204    value_delimiter = ',',
205    help = get_text("exclude_languages", None),
206  )]
207  exclude_languages: Vec<MiniStr>,
208
209  #[arg(
210    long,
211    value_name = "Vec<map_name>",
212    help_heading = "L10nResources",
213    value_name = "name1,name2,..",
214    value_delimiter = ',',
215    help = get_text("exclude_map_names", None),
216  )]
217  exclude_map_names: Vec<MiniStr>,
218}
219
220#[derive(Parser, Debug, Getters, Clone)]
221#[getset(get = "pub with_prefix")]
222pub struct HighlightOpt {
223  #[arg(long, help_heading = "HighlightKey", value_name = "Vec<String>",
224    help = get_text("base_name", None),
225  )]
226  base_name: Vec<MiniStr>,
227
228  #[arg(long, help_heading = "HighlightKey", value_name = "Vec<String>",
229    help = get_text("suffix", None),
230  )]
231  suffix: Vec<MiniStr>,
232
233  // --------
234  #[arg(long, help_heading = "HighlightValue", value_name = "Vec<bool>",
235    help = get_text("true_color", None),
236  )]
237  true_color: Vec<bool>,
238
239  #[arg(long, help_heading = "HighlightValue", value_name = "Vec<String>",
240    help = get_text("syntax_name", None),
241  )]
242  syntax_name: Vec<MiniStr>,
243
244  #[arg(long, help_heading = "HighlightValue", value_name = "Vec<String>",
245    help = get_text("theme_name", None),
246  )]
247  theme_name: Vec<MiniStr>,
248
249  #[arg(long, help_heading = "HighlightValue", value_name = "Vec<bool>",
250    help = get_text("background", None),
251  )]
252  background: Vec<bool>,
253
254  #[arg(
255    long,
256    help_heading = "HighlightValue",
257    value_name = r#"Vec<"/path/to/syntaxset-file">"#,
258    value_hint = clap::ValueHint::FilePath,
259    help = get_text("custom_syntax_set", None),
260  )]
261  custom_syntax_set: Vec<PathBuf>,
262
263  #[arg(
264    long,
265    help_heading = "HighlightValue",
266    value_name = r#"Vec<"/path/to/themeset-file">"#,
267    value_hint = clap::ValueHint::FilePath,
268    help = get_text("custom_theme_set", None),
269  )]
270  custom_theme_set: Vec<PathBuf>,
271
272  #[arg(long, help_heading = "HighlightValue Debug",
273    help = get_text("list_all_syntaxes", None),
274  )]
275  list_all_syntaxes: bool,
276
277  #[arg(long, help_heading = "HighlightValue Debug",
278    help = get_text("list_all_themes", None),
279  )]
280  list_all_themes: bool,
281}