Anki/rslib/i18n_helpers/src/bin/deprecate_ftl_entries.rs
RumovZ 855dc9d75b
Add Rust bin to deprecate unused ftl entries (#2364)
* Add Rust bin to deprecate unused ftl entries

* Align function names with bin names

* Support passing in multiple ftl roots

* Use source instead of jsons for deprecating

* Fix CargoRun not working more than once (dae)

* Add ftl:deprecate (dae)

* Deprecate some strings (dae)

This is not all of the strings that are currently unused

* Check json files before deprecating; add allowlist (dae)

The scheduler messages we'll probably want to reuse for the v2->v3
transition, so I'd prefer to keep them undeprecated for now.

* Deprecate old bury options (dae)

* Support gathering usages from Kotlin files for AnkiDroid (dae)

* Update json scripts (dae)

* Remove old deprecation headers

* Parameterize JSON roots to keep

* Tweak deprecation message (dae)
2023-02-07 11:56:14 +10:00

49 lines
1.5 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
/// Deprecate unused ftl entries by moving them to the bottom of the file and
/// adding a deprecation warning. An entry is considered unused if cannot be
/// found in a source or JSON file.
/// Arguments before `--` are roots of ftl files, arguments after that are
/// source roots. JSON roots must be preceded by `--keep` or `-k`.
fn main() {
let args = Arguments::new();
anki_i18n_helpers::garbage_collection::deprecate_ftl_entries(
&args.ftl_roots,
&args.source_roots,
&args.json_roots,
);
}
#[derive(Default)]
struct Arguments {
ftl_roots: Vec<String>,
source_roots: Vec<String>,
json_roots: Vec<String>,
}
impl Arguments {
fn new() -> Self {
let mut args = Self::default();
let mut past_separator = false;
let mut keep_flag = false;
for arg in std::env::args() {
match arg.as_str() {
"--" => {
past_separator = true;
}
"--keep" | "-k" => {
keep_flag = true;
}
_ if keep_flag => {
keep_flag = false;
args.json_roots.push(arg)
}
_ if past_separator => args.source_roots.push(arg),
_ => args.ftl_roots.push(arg),
};
}
args
}
}