Skip to content

Commit

Permalink
feat(tui): add --print-locales to print all available locales
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Oct 17, 2024
1 parent d81c314 commit f3c3930
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/trippy-tui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ pub enum TrippyAction {
PrintShellCompletions(Shell),
/// Generate a man page and exit.
PrintManPage,
/// Print all available locales and exit.
PrintLocales,
}

impl TrippyAction {
Expand All @@ -270,6 +272,8 @@ impl TrippyAction {
Self::PrintShellCompletions(shell)
} else if args.generate_man {
Self::PrintManPage
} else if args.print_locales {
Self::PrintLocales
} else {
Self::Trippy(TrippyConfig::from(args, privilege, pid)?)
})
Expand Down
6 changes: 5 additions & 1 deletion crates/trippy-tui/src/config/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::time::Duration;
#[command(name = "trip", author, version, about, long_about = None, arg_required_else_help(true), styles=Styles::styled())]
pub struct Args {
/// A space delimited list of hostnames and IPs to trace
#[arg(required_unless_present_any(["print_tui_theme_items", "print_tui_binding_commands", "print_config_template", "generate", "generate_man"]))]
#[arg(required_unless_present_any(["print_tui_theme_items", "print_tui_binding_commands", "print_config_template", "generate", "generate_man", "print_locales"]))]
pub targets: Vec<String>,

/// Config file
Expand Down Expand Up @@ -260,6 +260,10 @@ pub struct Args {
#[arg(long)]
pub print_config_template: bool,

/// Print all locales and exit
#[arg(long)]
pub print_locales: bool,

/// The debug log format [default: pretty]
#[arg(long)]
pub log_format: Option<LogFormat>,
Expand Down
1 change: 1 addition & 0 deletions crates/trippy-tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub fn trippy() -> anyhow::Result<()> {
TrippyAction::PrintConfigTemplate => print::print_config_template(),
TrippyAction::PrintManPage => print::print_man_page()?,
TrippyAction::PrintShellCompletions(shell) => print::print_shell_completions(shell)?,
TrippyAction::PrintLocales => print::print_locales(),
}
Ok(())
}
5 changes: 5 additions & 0 deletions crates/trippy-tui/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub fn locale() -> String {
rust_i18n::locale().to_string()
}

/// Get all available locales.
pub fn available_locales() -> Vec<&'static str> {
rust_i18n::available_locales!()
}

fn set_locale_inner(locale: &str) {
let all_locales = rust_i18n::available_locales!();
if all_locales.contains(&locale) {
Expand Down
7 changes: 7 additions & 0 deletions crates/trippy-tui/src/print.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::config::{Args, TuiCommandItem, TuiThemeItem};
use crate::locale::available_locales;
use clap::CommandFactory;
use clap_complete::Shell;
use itertools::Itertools;
use std::process;
use strum::VariantNames;

Expand Down Expand Up @@ -29,6 +31,11 @@ pub fn print_man_page() -> anyhow::Result<()> {
process::exit(0);
}

pub fn print_locales() {
println!("TUI locales: {}", available_locales().iter().join(", "));
process::exit(0);
}

fn tui_theme_items() -> String {
format!(
"TUI theme color items: {}",
Expand Down

0 comments on commit f3c3930

Please sign in to comment.