Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gettext for clap #254

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add gettext for clap
  • Loading branch information
fox0 committed Sep 25, 2024
commit 162e0be153eb369f82e15c18403d9a63bb392a7b
20 changes: 12 additions & 8 deletions awk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::compiler::compile_program;
use crate::interpreter::interpret;
use clap::Parser;
use compiler::SourceFile;
use gettextrs::{bind_textdomain_codeset, textdomain};
use gettextrs::{bind_textdomain_codeset, gettext, textdomain};
use plib::PROJECT_NAME;
use std::error::Error;
use std::fmt::Display;
Expand All @@ -22,19 +22,23 @@ mod interpreter;
mod program;
mod regex;

/// awk - pattern scanning and processing language
#[derive(Parser)]
struct Args {
/// Define the input field separator
#[arg(short = 'F')]
#[arg(short = 'F', help = gettext("Define the input field separator"))]
separator_string: Option<String>,

/// Specify the program files
#[arg(short = 'f', action = clap::ArgAction::Append)]
#[arg(
short = 'f',
action = clap::ArgAction::Append,
help = gettext("Specify the program files")
)]
program_files: Vec<String>,

/// Globals assignments, executed before the start of the program
#[arg(short = 'v', action = clap::ArgAction::Append)]
#[arg(
short = 'v',
action = clap::ArgAction::Append,
help = gettext("Globals assignments, executed before the start of the program")
)]
assignments: Vec<String>,

arguments: Vec<String>,
Expand Down
23 changes: 15 additions & 8 deletions datetime/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,29 @@

use chrono::{DateTime, Datelike, Local, LocalResult, TimeZone, Utc};
use clap::Parser;
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;

const DEF_TIMESTR: &str = "%a %b %e %H:%M:%S %Z %Y";

/// date - write the date and time
#[derive(Parser)]
#[command(version, about)]
#[command(version, about = gettext("date - write the date and time"))]
struct Args {
/// Perform operations as if the TZ env var was set to the string "UTC0"
#[arg(short, long)]
#[arg(
short,
long,
help = gettext(
"Perform operations as if the TZ env var was set to the string \"UTC0\""
)
)]
utc: bool,

/// If prefixed with '+', Display the current time in the given FORMAT,
/// as in strftime(3). Otherwise, set the current time to the given
/// string.
#[arg(
help = gettext(
"If prefixed with '+', Display the current time in the given FORMAT, \
as in strftime(3). Otherwise, set the current time to the given string"
)
)]
timestr: Option<String>,
}

Expand Down
11 changes: 6 additions & 5 deletions datetime/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
//

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;
use std::{thread, time};

/// sleep - suspend execution for an interval
#[derive(Parser)]
#[command(version, about)]
#[command(version, about = gettext("sleep - suspend execution for an interval"))]
struct Args {
/// Number of seconds to sleep
#[arg(value_parser = clap::value_parser!(u64).range(1..))]
#[arg(
value_parser = clap::value_parser!(u64).range(1..),
help = gettext("Number of seconds to sleep")
)]
seconds: u64,
}

Expand Down
23 changes: 16 additions & 7 deletions datetime/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,30 @@ use std::time::Instant;

use clap::Parser;

use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;

#[derive(Parser)]
#[command(version, about)]
#[command(
version,
about = gettext("time - time a simple command or give resource usage")
)]
struct Args {
/// Write timing output to standard error in POSIX format
#[arg(short, long)]
#[arg(
short,
long,
help = gettext("Write timing output to standard error in POSIX format")
)]
posix: bool,

/// The utility to be invoked
#[arg(help = gettext("The utility to be invoked"))]
utility: String,

/// Arguments for the utility
#[arg(name = "ARGUMENT", trailing_var_arg = true)]
#[arg(
name = "ARGUMENT",
trailing_var_arg = true,
help = gettext("Arguments for the utility")
)]
arguments: Vec<String>,
}

Expand Down
5 changes: 2 additions & 3 deletions dev/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ use std::{
};

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use object::{
archive,
build::elf::{Builder, Section, SectionData},
elf,
};
use plib::PROJECT_NAME;

/// strip - remove unnecessary information from strippable files
#[derive(Parser)]
#[command(version, about)]
#[command(version, about = gettext("strip - remove unnecessary information from strippable files"))]
struct Args {
input_files: Vec<OsString>,
}
Expand Down
15 changes: 9 additions & 6 deletions file/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@
// continue to the next file, rather than stopping.

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;
use std::io::{self, Read, Write};
use std::path::PathBuf;

/// cat - concatenate and print files
#[derive(Parser)]
#[command(version, about)]
#[command(version, about = gettext("cat - concatenate and print files"))]
struct Args {
/// Disable output buffering (a no-op, for POSIX compat.)
#[arg(short, long, default_value_t = true)]
#[arg(
short,
long,
default_value_t = true,
help = gettext("Disable output buffering (a no-op, for POSIX compat)")
)]
unbuffered: bool,

/// Files to read as input. Use "-" or no-args for stdin.
#[arg(help = gettext("Files to read as input. Use '-' or no-args for stdin"))]
files: Vec<PathBuf>,
}

Expand Down
36 changes: 27 additions & 9 deletions file/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,46 @@
//

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;
use std::io::{self, ErrorKind, Read};
use std::path::PathBuf;
use std::process::ExitCode;

/// cmp - compare two files
#[derive(Parser)]
#[command(version, about)]
#[command(version, about = gettext("cmp - compare two files"))]
struct Args {
/// Write the byte number (decimal) and the differing bytes (octal) for each difference.
#[arg(short = 'l', long, group = "verbosity")]
#[arg(
short = 'l',
long,
group = "verbosity",
help = gettext(
"Write the byte number (decimal) and the differing bytes (octal) for each difference"
)
)]
verbose: bool,

/// Write nothing for differing files; return exit status only.
#[arg(short, long, alias = "quiet", group = "verbosity")]
#[arg(
short,
long,
alias = "quiet",
group = "verbosity",
help = gettext("Write nothing for differing files; return exit status only")
)]
silent: bool,

/// A pathname of the first file to be compared. If file1 is '-', the standard input shall be used.
#[arg(
help = gettext(
"A pathname of the first file to be compared. If file1 is '-', the standard input shall be used"
)
)]
file1: PathBuf,

/// A pathname of the second file to be compared. If file2 is '-', the standard input shall be used.
#[arg(
help = gettext(
"A pathname of the second file to be compared. If file2 is '-', the standard input shall be used"
)
)]
file2: PathBuf,
}

Expand Down
44 changes: 31 additions & 13 deletions file/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;
use regex::Regex;
use std::{
Expand All @@ -21,31 +21,49 @@ use std::{
path::PathBuf,
};

/// file - determine file type
#[derive(Parser)]
#[command(version, about, disable_help_flag = true)]
#[command(
version,
disable_help_flag = true,
about = gettext("file - determine file type")
)]
struct Args {
#[arg(long, action = clap::ArgAction::HelpLong)]
help: Option<bool>,

/// Apply default position-sensitive system tests and context-sensitive system tests to the file.
#[arg(short = 'd', long)]
#[arg(
short = 'd',
long,
help = gettext(
"Apply default position-sensitive system tests and context-sensitive system tests to the file"
)
)]
default_tests: bool,

/// Identify symbolic link with non existent file as symbolic link
#[arg(short = 'h', long)]
#[arg(
short = 'h',
long,
help = gettext("Identify symbolic link with non existent file as symbolic link")
)]
identify_as_symbolic_link: bool,

/// Don't perform further classification on regular file
#[arg(short = 'i', long)]
#[arg(
short = 'i',
long,
help = gettext("Don't perform further classification on regular file")
)]
no_further_file_classification: bool,

/// File containing position-sensitive tests
#[arg(short = 'm')]
#[arg(
short = 'm',
help = gettext("File containing position-sensitive tests")
)]
test_file1: Option<PathBuf>,

/// File containing additional position-sensitive tests
#[arg(short = 'M')]
#[arg(
short = 'M',
help = gettext("File containing additional position-sensitive tests")
)]
test_file2: Option<PathBuf>,

files: Vec<String>,
Expand Down
Loading