Skip to content

Commit 17472a5

Browse files
committed
localize clap parsing error
1 parent 0952346 commit 17472a5

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

Cargo.lock

Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ i18n-embed = { version = "0.16.0", features = [
7575
i18n-embed-fl = "0.10.0"
7676
rust-embed = "8.9.0"
7777
macro-vis = "0.1.1"
78+
clap-i18n-richformatter = { git = "https://github.com/Sk7Str1p3/clap-i18n-richformatter-0.1.4" }
7879

7980
[dev-dependencies]
8081
criterion = "0.7.0"

src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use anyhow::Result;
44
use clap::{CommandFactory, Parser};
5+
use clap_i18n_richformatter::{init_clap_rich_formatter_localizer, ClapI18nRichFormatter};
56
use human_panic::setup_panic;
67
use onefetch::cli::{self, CliOptions};
78
use onefetch::info::build_info;
@@ -11,11 +12,15 @@ use std::io;
1112
fn main() -> Result<()> {
1213
setup_panic!();
1314
onefetch::i18n::init()?;
15+
init_clap_rich_formatter_localizer();
1416

1517
#[cfg(windows)]
1618
enable_ansi_support::enable_ansi_support()?;
1719

18-
let cli_options = cli::CliOptions::parse();
20+
let cli_options = cli::CliOptions::try_parse().map_err(|e| {
21+
let e = e.apply::<ClapI18nRichFormatter>();
22+
e.exit()
23+
}).unwrap();
1924

2025
if cli_options.other.languages {
2126
return cli::print_supported_languages();

0 commit comments

Comments
 (0)