Skip to content

Commit b579853

Browse files
committed
feat: translate cli
TODO: deal with `default` and `possible values`
1 parent 2386d1b commit b579853

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

locales/en-US/cli.ftl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
cli-input = Run as if onefetch was started in <input> instead of the current working directory
22
3+
cli-about = Command-line Git information tool
4+
cli-usage-header = Usage
5+
cli-arguments-header = Arguments
6+
cli-options-header = Options
7+
cli-help = Print help (see more with '--help', see a summary with '-h')
8+
cli-version = Print version
9+
310
# Value name
11+
cli-value-input = INPUT
412
cli-value-num = NUM
513
cli-value-field = FIELD
614
cli-value-regex = REGEX

locales/ru-RU/cli.ftl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
cli-input = Запустить так, как будто onefetch был запущен в <input> вместо текущего рабочего каталога
1+
cli-input = Запустить так, как будто onefetch был запущен в <ввод> вместо текущего рабочего каталога
2+
3+
cli-about = Инструмент командной строки для получения информации о Git
4+
cli-usage-header = Использование
5+
cli-arguments-header = Аргументы
6+
cli-options-header = Опции
7+
cli-help = Показать помощь (подробнее с '--help', кратко с '-h')
8+
cli-version = Показать версию
29
310
# Value name
11+
cli-value-input = ВВОД
412
cli-value-num = КОЛ-ВО
513
cli-value-field = ПОЛЕ
614
cli-value-regex = РЕГ. ВЫРАЖЕНИЕ

src/cli.rs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::info::langs::language::{Language, LanguageType};
33
use crate::info::utils::info_field::InfoType;
44
use crate::ui::printer::SerializationFormat;
55
use anyhow::Result;
6-
use clap::builder::PossibleValuesParser;
6+
use clap::builder::{PossibleValuesParser, Styles};
77
use clap::builder::TypedValueParser as _;
88
use clap::{value_parser, Args, Command, Parser, ValueHint};
99
use clap_complete::{generate, Generator, Shell};
@@ -22,15 +22,48 @@ const COLOR_RESOLUTIONS: [&str; 5] = ["16", "32", "64", "128", "256"];
2222
pub const NO_BOTS_DEFAULT_REGEX_PATTERN: &str = r"(?:-|\s)[Bb]ot$|\[[Bb]ot\]";
2323

2424
#[derive(Clone, Debug, Parser, PartialEq, Eq)]
25-
#[command(version, about)]
25+
#[command(
26+
about = tr!("cli-about"),
27+
version,
28+
disable_help_flag = true,
29+
disable_version_flag = true,
30+
help_template = format!("\
31+
{{before-help}}{{about-with-newline}}\
32+
\n{}{}:{} {{usage}}
33+
\n{{all-args}}{{after-help}}\
34+
",
35+
Styles::default().get_usage().render(),
36+
tr!("cli-usage-header"),
37+
Styles::default().get_usage().render_reset()
38+
),
39+
next_help_heading = tr!("cli-arguments-header"),
40+
override_usage = format!("onefetch [{}] [{}]", tr!("cli-options-header").to_owned().to_uppercase(), tr!("cli-value-input"))
41+
)]
2642
pub struct CliOptions {
2743
#[arg(
2844
default_value = ".",
2945
hide_default_value = true,
3046
value_hint = ValueHint::DirPath,
31-
help = tr!("cli-input")
47+
help = tr!("cli-input"),
48+
value_name = tr!("cli-value-input")
3249
)]
3350
pub input: PathBuf,
51+
#[arg(
52+
action = clap::ArgAction::Help,
53+
long,
54+
short,
55+
help = tr!("cli-help"),
56+
help_heading = tr!("cli-options-header")
57+
)]
58+
pub help: Option<bool>,
59+
#[arg(
60+
action = clap::ArgAction::Version,
61+
long,
62+
short = 'V',
63+
help = tr!("cli-version"),
64+
help_heading = tr!("cli-options-header")
65+
)]
66+
pub version: Option<bool>,
3467
#[command(flatten)]
3568
pub info: InfoCliOptions,
3669
#[command(flatten)]
@@ -203,6 +236,8 @@ pub struct OtherCliOptions {
203236
impl Default for CliOptions {
204237
fn default() -> CliOptions {
205238
CliOptions {
239+
help: None,
240+
version: None,
206241
input: PathBuf::from("."),
207242
info: InfoCliOptions::default(),
208243
text_formatting: TextForamttingCliOptions::default(),

0 commit comments

Comments
 (0)