Skip to content

Commit b7cd1ab

Browse files
committed
Refactor
1 parent b6d7fc7 commit b7cd1ab

File tree

5 files changed

+361
-413
lines changed

5 files changed

+361
-413
lines changed

src/cli/src/main.rs

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use extractor::ftl::consts::{
33
CommentsKeyModes, DEFAULT_EXCLUDE_DIRS, DEFAULT_FTL_FILENAME, DEFAULT_I18N_KEYS,
44
DEFAULT_IGNORE_ATTRIBUTES, DEFAULT_IGNORE_KWARGS, LineEndings,
55
};
6+
use extractor::ftl::ftl_extractor::{ExtractConfig, extract};
7+
68
use hashbrown::HashSet;
79
use mimalloc::MiMalloc;
810
use std::path::PathBuf;
@@ -99,7 +101,7 @@ fn main() {
99101
let cli = Cli::parse();
100102
let start_time = std::time::Instant::now();
101103

102-
match &cli.command {
104+
match cli.command {
103105
Some(Commands::Extract {
104106
code_path,
105107
output_path,
@@ -118,49 +120,61 @@ fn main() {
118120
line_endings,
119121
dry_run,
120122
}) => {
121-
use extractor::ftl::ftl_extractor::extract;
122-
123123
println!("Code path: {}", code_path.display());
124124
println!("Output path: {}", output_path.display());
125-
let statistics = extract(
125+
126+
let mut i18n_keys_set: HashSet<String> = HashSet::from_iter(i18n_keys);
127+
i18n_keys_set.extend(i18n_keys_append);
128+
129+
let mut exclude_dirs_set: HashSet<String> = HashSet::from_iter(exclude_dirs);
130+
exclude_dirs_set.extend(exclude_dirs_append);
131+
132+
let mut ignore_attributes_set: HashSet<String> = HashSet::from_iter(ignore_attributes);
133+
ignore_attributes_set.extend(append_ignore_attributes);
134+
135+
let config = ExtractConfig {
126136
code_path,
127137
output_path,
128-
language.to_owned(),
129-
HashSet::from_iter(i18n_keys.to_owned()),
130-
HashSet::from_iter(i18n_keys_append.to_owned()),
131-
HashSet::from_iter(i18n_keys_prefix.to_owned()),
132-
HashSet::from_iter(exclude_dirs.to_owned()),
133-
HashSet::from_iter(exclude_dirs_append.to_owned()),
134-
HashSet::from_iter(ignore_attributes.to_owned()),
135-
HashSet::from_iter(append_ignore_attributes.to_owned()),
136-
HashSet::from_iter(ignore_kwargs.to_owned()),
137-
comment_junks.to_owned(),
138+
languages: language,
139+
i18n_keys: i18n_keys_set,
140+
i18n_keys_prefix: HashSet::from_iter(i18n_keys_prefix),
141+
exclude_dirs: exclude_dirs_set,
142+
ignore_attributes: ignore_attributes_set,
143+
ignore_kwargs: HashSet::from_iter(ignore_kwargs),
144+
comment_junks,
138145
default_ftl_file,
139-
comment_keys_mode.to_owned(),
140-
line_endings.to_owned(),
141-
dry_run.to_owned(),
142-
cli.silent,
143-
)
144-
.unwrap();
145-
146-
if cli.verbose {
147-
println!("Extraction statistics:");
148-
println!(" - Py files count: {}", statistics.py_files_count);
149-
println!(" - FTL files count: {:?}", statistics.ftl_files_count);
150-
println!(
151-
" - FTL keys in code: {:?}",
152-
statistics.ftl_in_code_keys_count
153-
);
154-
println!(
155-
" - FTL keys stored: {:?}",
156-
statistics.ftl_stored_keys_count
157-
);
158-
println!(" - FTL keys updated: {:?}", statistics.ftl_keys_updated);
159-
println!(" - FTL keys added: {:?}", statistics.ftl_keys_added);
160-
println!(
161-
" - FTL keys commented: {:?}",
162-
statistics.ftl_keys_commented
163-
);
146+
comment_keys_mode,
147+
line_endings,
148+
dry_run,
149+
silent: cli.silent,
150+
};
151+
152+
match extract(config) {
153+
Ok(statistics) => {
154+
if cli.verbose {
155+
println!("Extraction statistics:");
156+
println!(" - Py files count: {}", statistics.py_files_count);
157+
println!(" - FTL files count: {:?}", statistics.ftl_files_count);
158+
println!(
159+
" - FTL keys in code: {}",
160+
statistics.ftl_in_code_keys_count
161+
);
162+
println!(
163+
" - FTL keys stored: {:?}",
164+
statistics.ftl_stored_keys_count
165+
);
166+
println!(" - FTL keys updated: {:?}", statistics.ftl_keys_updated);
167+
println!(" - FTL keys added: {:?}", statistics.ftl_keys_added);
168+
println!(
169+
" - FTL keys commented: {:?}",
170+
statistics.ftl_keys_commented
171+
);
172+
}
173+
}
174+
Err(e) => {
175+
eprintln!("Error during extraction: {}", e);
176+
std::process::exit(1);
177+
}
164178
}
165179
}
166180
None => {

0 commit comments

Comments
 (0)