Skip to content

Commit 6917075

Browse files
authored
Merge pull request #254 from fox0/main
Add gettext for clap
2 parents 2ca125f + 2a5e896 commit 6917075

File tree

26 files changed

+435
-229
lines changed

26 files changed

+435
-229
lines changed

awk/src/main.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::compiler::compile_program;
1111
use crate::interpreter::interpret;
1212
use clap::Parser;
1313
use compiler::SourceFile;
14-
use gettextrs::{bind_textdomain_codeset, textdomain};
14+
use gettextrs::{bind_textdomain_codeset, gettext, textdomain};
1515
use plib::PROJECT_NAME;
1616
use std::error::Error;
1717
use std::fmt::Display;
@@ -22,19 +22,24 @@ mod interpreter;
2222
mod program;
2323
mod regex;
2424

25-
/// awk - pattern scanning and processing language
2625
#[derive(Parser)]
26+
#[command(version, about = gettext("awk - pattern scanning and processing language"))]
2727
struct Args {
28-
/// Define the input field separator
29-
#[arg(short = 'F')]
28+
#[arg(short = 'F', help = gettext("Define the input field separator"))]
3029
separator_string: Option<String>,
3130

32-
/// Specify the program files
33-
#[arg(short = 'f', action = clap::ArgAction::Append)]
31+
#[arg(
32+
short = 'f',
33+
action = clap::ArgAction::Append,
34+
help = gettext("Specify the program files")
35+
)]
3436
program_files: Vec<String>,
3537

36-
/// Globals assignments, executed before the start of the program
37-
#[arg(short = 'v', action = clap::ArgAction::Append)]
38+
#[arg(
39+
short = 'v',
40+
action = clap::ArgAction::Append,
41+
help = gettext("Globals assignments, executed before the start of the program")
42+
)]
3843
assignments: Vec<String>,
3944

4045
arguments: Vec<String>,

datetime/date.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,29 @@
1313

1414
use chrono::{DateTime, Datelike, Local, LocalResult, TimeZone, Utc};
1515
use clap::Parser;
16-
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
16+
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
1717
use plib::PROJECT_NAME;
1818

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

21-
/// date - write the date and time
2221
#[derive(Parser)]
23-
#[command(version, about)]
22+
#[command(version, about = gettext("date - write the date and time"))]
2423
struct Args {
25-
/// Perform operations as if the TZ env var was set to the string "UTC0"
26-
#[arg(short, long)]
24+
#[arg(
25+
short,
26+
long,
27+
help = gettext(
28+
"Perform operations as if the TZ env var was set to the string \"UTC0\""
29+
)
30+
)]
2731
utc: bool,
2832

29-
/// If prefixed with '+', Display the current time in the given FORMAT,
30-
/// as in strftime(3). Otherwise, set the current time to the given
31-
/// string.
33+
#[arg(
34+
help = gettext(
35+
"If prefixed with '+', Display the current time in the given FORMAT, \
36+
as in strftime(3). Otherwise, set the current time to the given string"
37+
)
38+
)]
3239
timestr: Option<String>,
3340
}
3441

datetime/sleep.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
//
99

1010
use clap::Parser;
11-
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
11+
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
1212
use plib::PROJECT_NAME;
1313
use std::{thread, time};
1414

15-
/// sleep - suspend execution for an interval
1615
#[derive(Parser)]
17-
#[command(version, about)]
16+
#[command(version, about = gettext("sleep - suspend execution for an interval"))]
1817
struct Args {
19-
/// Number of seconds to sleep
20-
#[arg(value_parser = clap::value_parser!(u64).range(1..))]
18+
#[arg(
19+
value_parser = clap::value_parser!(u64).range(1..),
20+
help = gettext("Number of seconds to sleep")
21+
)]
2122
seconds: u64,
2223
}
2324

datetime/time.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,30 @@ use std::time::Instant;
1313

1414
use clap::Parser;
1515

16-
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
16+
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
1717
use plib::PROJECT_NAME;
1818

1919
#[derive(Parser)]
20-
#[command(version, about)]
20+
#[command(
21+
version,
22+
about = gettext("time - time a simple command or give resource usage")
23+
)]
2124
struct Args {
22-
/// Write timing output to standard error in POSIX format
23-
#[arg(short, long)]
25+
#[arg(
26+
short,
27+
long,
28+
help = gettext("Write timing output to standard error in POSIX format")
29+
)]
2430
posix: bool,
2531

26-
/// The utility to be invoked
32+
#[arg(help = gettext("The utility to be invoked"))]
2733
utility: String,
2834

29-
/// Arguments for the utility
30-
#[arg(name = "ARGUMENT", trailing_var_arg = true)]
35+
#[arg(
36+
name = "ARGUMENT",
37+
trailing_var_arg = true,
38+
help = gettext("Arguments for the utility")
39+
)]
3140
arguments: Vec<String>,
3241
}
3342

dev/strip.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ use std::{
1313
};
1414

1515
use clap::Parser;
16-
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
16+
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
1717
use object::{
1818
archive,
1919
build::elf::{Builder, Section, SectionData},
2020
elf,
2121
};
2222
use plib::PROJECT_NAME;
2323

24-
/// strip - remove unnecessary information from strippable files
2524
#[derive(Parser)]
26-
#[command(version, about)]
25+
#[command(version, about = gettext("strip - remove unnecessary information from strippable files"))]
2726
struct Args {
2827
input_files: Vec<OsString>,
2928
}

file/cat.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,23 @@
1313
// continue to the next file, rather than stopping.
1414

1515
use clap::Parser;
16-
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
16+
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
1717
use plib::PROJECT_NAME;
1818
use std::io::{self, Read, Write};
1919
use std::path::PathBuf;
2020

21-
/// cat - concatenate and print files
2221
#[derive(Parser)]
23-
#[command(version, about)]
22+
#[command(version, about = gettext("cat - concatenate and print files"))]
2423
struct Args {
25-
/// Disable output buffering (a no-op, for POSIX compat.)
26-
#[arg(short, long, default_value_t = true)]
24+
#[arg(
25+
short,
26+
long,
27+
default_value_t = true,
28+
help = gettext("Disable output buffering (a no-op, for POSIX compat)")
29+
)]
2730
unbuffered: bool,
2831

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

file/cmp.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,46 @@
88
//
99

1010
use clap::Parser;
11-
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
11+
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
1212
use plib::PROJECT_NAME;
1313
use std::io::{self, ErrorKind, Read};
1414
use std::path::PathBuf;
1515
use std::process::ExitCode;
1616

17-
/// cmp - compare two files
1817
#[derive(Parser)]
19-
#[command(version, about)]
18+
#[command(version, about = gettext("cmp - compare two files"))]
2019
struct Args {
21-
/// Write the byte number (decimal) and the differing bytes (octal) for each difference.
22-
#[arg(short = 'l', long, group = "verbosity")]
20+
#[arg(
21+
short = 'l',
22+
long,
23+
group = "verbosity",
24+
help = gettext(
25+
"Write the byte number (decimal) and the differing bytes (octal) for each difference"
26+
)
27+
)]
2328
verbose: bool,
2429

25-
/// Write nothing for differing files; return exit status only.
26-
#[arg(short, long, alias = "quiet", group = "verbosity")]
30+
#[arg(
31+
short,
32+
long,
33+
alias = "quiet",
34+
group = "verbosity",
35+
help = gettext("Write nothing for differing files; return exit status only")
36+
)]
2737
silent: bool,
2838

29-
/// A pathname of the first file to be compared. If file1 is '-', the standard input shall be used.
39+
#[arg(
40+
help = gettext(
41+
"A pathname of the first file to be compared. If file1 is '-', the standard input shall be used"
42+
)
43+
)]
3044
file1: PathBuf,
3145

32-
/// A pathname of the second file to be compared. If file2 is '-', the standard input shall be used.
46+
#[arg(
47+
help = gettext(
48+
"A pathname of the second file to be compared. If file2 is '-', the standard input shall be used"
49+
)
50+
)]
3351
file2: PathBuf,
3452
}
3553

file/file.rs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010

1111
use clap::Parser;
12-
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
12+
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
1313
use plib::PROJECT_NAME;
1414
use regex::Regex;
1515
use std::{
@@ -21,31 +21,49 @@ use std::{
2121
path::PathBuf,
2222
};
2323

24-
/// file - determine file type
2524
#[derive(Parser)]
26-
#[command(version, about, disable_help_flag = true)]
25+
#[command(
26+
version,
27+
disable_help_flag = true,
28+
about = gettext("file - determine file type")
29+
)]
2730
struct Args {
2831
#[arg(long, action = clap::ArgAction::HelpLong)]
2932
help: Option<bool>,
3033

31-
/// Apply default position-sensitive system tests and context-sensitive system tests to the file.
32-
#[arg(short = 'd', long)]
34+
#[arg(
35+
short = 'd',
36+
long,
37+
help = gettext(
38+
"Apply default position-sensitive system tests and context-sensitive system tests to the file"
39+
)
40+
)]
3341
default_tests: bool,
3442

35-
/// Identify symbolic link with non existent file as symbolic link
36-
#[arg(short = 'h', long)]
43+
#[arg(
44+
short = 'h',
45+
long,
46+
help = gettext("Identify symbolic link with non existent file as symbolic link")
47+
)]
3748
identify_as_symbolic_link: bool,
3849

39-
/// Don't perform further classification on regular file
40-
#[arg(short = 'i', long)]
50+
#[arg(
51+
short = 'i',
52+
long,
53+
help = gettext("Don't perform further classification on regular file")
54+
)]
4155
no_further_file_classification: bool,
4256

43-
/// File containing position-sensitive tests
44-
#[arg(short = 'm')]
57+
#[arg(
58+
short = 'm',
59+
help = gettext("File containing position-sensitive tests")
60+
)]
4561
test_file1: Option<PathBuf>,
4662

47-
/// File containing additional position-sensitive tests
48-
#[arg(short = 'M')]
63+
#[arg(
64+
short = 'M',
65+
help = gettext("File containing additional position-sensitive tests")
66+
)]
4967
test_file2: Option<PathBuf>,
5068

5169
files: Vec<String>,

0 commit comments

Comments
 (0)