Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions src/uu/nproc/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ nproc-about = Print the number of cores available to the current process.
If the OMP_NUM_THREADS or OMP_THREAD_LIMIT environment variables are set, then
they will determine the minimum and maximum returned value respectively.
nproc-usage = nproc [OPTIONS]...

# Error messages
nproc-error-invalid-number = { $value } is not a valid number: { $error }

# Help text for command-line arguments
nproc-help-all = print the number of cores available to the system
nproc-help-ignore = ignore up to N cores
11 changes: 11 additions & 0 deletions src/uu/nproc/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
nproc-about = Affiche le nombre de cœurs disponibles pour le processus actuel.
Si les variables d'environnement OMP_NUM_THREADS ou OMP_THREAD_LIMIT sont définies,
elles détermineront respectivement la valeur minimale et maximale retournée.
nproc-usage = nproc [OPTIONS]...

# Messages d'erreur
nproc-error-invalid-number = { $value } n'est pas un nombre valide : { $error }

# Texte d'aide pour les arguments de ligne de commande
nproc-help-all = affiche le nombre de cœurs disponibles pour le système
nproc-help-ignore = ignore jusqu'à N cœurs
17 changes: 12 additions & 5 deletions src/uu/nproc/src/nproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
// spell-checker:ignore (ToDO) NPROCESSORS nprocs numstr sysconf

use clap::{Arg, ArgAction, Command};
use std::collections::HashMap;
use std::{env, thread};
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};

#[cfg(any(target_os = "linux", target_os = "android"))]
pub const _SC_NPROCESSORS_CONF: libc::c_int = 83;
Expand All @@ -29,12 +30,18 @@
let matches = uu_app().try_get_matches_from(args)?;

let ignore = match matches.get_one::<String>(OPT_IGNORE) {
Some(numstr) => match numstr.trim().parse() {
Some(numstr) => match numstr.trim().parse::<usize>() {
Ok(num) => num,
Err(e) => {
return Err(USimpleError::new(
1,
format!("{} is not a valid number: {e}", numstr.quote()),
get_message_with_args(
"nproc-error-invalid-number",
HashMap::from([
("value".to_string(), numstr.quote().to_string()),
("error".to_string(), e.to_string()),
]),
),

Check warning on line 44 in src/uu/nproc/src/nproc.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/nproc/src/nproc.rs#L38-L44

Added lines #L38 - L44 were not covered by tests
));
}
},
Expand Down Expand Up @@ -98,14 +105,14 @@
.arg(
Arg::new(OPT_ALL)
.long(OPT_ALL)
.help("print the number of cores available to the system")
.help(get_message("nproc-help-all"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(OPT_IGNORE)
.long(OPT_IGNORE)
.value_name("N")
.help("ignore up to N cores"),
.help(get_message("nproc-help-ignore")),
)
}

Expand Down
Loading