1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #8211 from sylvestre/l10n-split

'l10n: port split for translation + add french
This commit is contained in:
Daniel Hofstetter 2025-06-24 15:31:11 +02:00 committed by GitHub
commit bc459d1e51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 233 additions and 74 deletions

View file

@ -14,3 +14,48 @@ split-after-help = Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...;
- l/K/N output Kth of N to stdout without splitting lines/records
- r/N like 'l' but use round robin distribution
- r/K/N likewise but only output Kth of N to stdout
# Error messages
split-error-suffix-not-parsable = invalid suffix length: { $value }
split-error-suffix-contains-separator = invalid suffix { $value }, contains directory separator
split-error-suffix-too-small = the suffix length needs to be at least { $length }
split-error-multi-character-separator = multi-character separator { $separator }
split-error-multiple-separator-characters = multiple separator characters specified
split-error-filter-with-kth-chunk = --filter does not process a chunk extracted to stdout
split-error-invalid-io-block-size = invalid IO block size: { $size }
split-error-not-supported = --filter is currently not supported in this platform
split-error-invalid-number-of-chunks = invalid number of chunks: { $chunks }
split-error-invalid-chunk-number = invalid chunk number: { $chunk }
split-error-invalid-number-of-lines = invalid number of lines: { $error }
split-error-invalid-number-of-bytes = invalid number of bytes: { $error }
split-error-cannot-split-more-than-one-way = cannot split in more than one way
split-error-overflow = Overflow
split-error-output-file-suffixes-exhausted = output file suffixes exhausted
split-error-numerical-suffix-start-too-large = numerical suffix start value is too large for the suffix length
split-error-cannot-open-for-reading = cannot open { $file } for reading
split-error-would-overwrite-input = { $file } would overwrite input; aborting
split-error-cannot-determine-input-size = { $input }: cannot determine input size
split-error-cannot-determine-file-size = { $input }: cannot determine file size
split-error-cannot-read-from-input = { $input }: cannot read from input : { $error }
split-error-input-output-error = input/output error
split-error-unable-to-open-file = unable to open { $file }; aborting
split-error-unable-to-reopen-file = unable to re-open { $file }; aborting
split-error-file-descriptor-limit = at file descriptor limit, but no file descriptor left to close. Closed { $count } writers before.
split-error-shell-process-returned = Shell process returned { $code }
split-error-shell-process-terminated = Shell process terminated by signal
# Help messages for command-line options
split-help-bytes = put SIZE bytes per output file
split-help-line-bytes = put at most SIZE bytes of lines per output file
split-help-lines = put NUMBER lines/records per output file
split-help-number = generate CHUNKS output files; see explanation below
split-help-additional-suffix = additional SUFFIX to append to output file names
split-help-filter = write to shell COMMAND; file name is $FILE (Currently not implemented for Windows)
split-help-elide-empty-files = do not generate empty output files with '-n'
split-help-numeric-suffixes-short = use numeric suffixes starting at 0, not alphabetic
split-help-numeric-suffixes = same as -d, but allow setting the start value
split-help-hex-suffixes-short = use hex suffixes starting at 0, not alphabetic
split-help-hex-suffixes = same as -x, but allow setting the start value
split-help-suffix-length = generate suffixes of length N (default 2)
split-help-verbose = print a diagnostic just before each output file is opened
split-help-separator = use SEP instead of newline as the record separator; '\\0' (zero) specifies the NUL character

View file

@ -0,0 +1,61 @@
split-about = Créer des fichiers de sortie contenant des sections consécutives ou entrelacées de l'entrée
split-usage = split [OPTION]... [ENTRÉE [PRÉFIXE]]
split-after-help = Sortir des morceaux de taille fixe d'ENTRÉE vers PREFIXEaa, PREFIXEab, ...; la taille par défaut est 1000, et le PRÉFIXE par défaut est 'x'. Sans ENTRÉE, ou quand ENTRÉE est -, lire l'entrée standard.
L'argument TAILLE est un entier et une unité optionnelle (exemple: 10K est 10*1024).
Les unités sont K,M,G,T,P,E,Z,Y,R,Q (puissances de 1024) ou KB,MB,... (puissances de 1000).
Les préfixes binaires peuvent être utilisés aussi: KiB=K, MiB=M, et ainsi de suite.
CHUNKS peut être:
- N diviser en N fichiers basé sur la taille de l'entrée
- K/N sortir le Kème de N vers stdout
- l/N diviser en N fichiers sans diviser les lignes/enregistrements
- l/K/N sortir le Kème de N vers stdout sans diviser les lignes/enregistrements
- r/N comme 'l' mais utiliser la distribution round robin
- r/K/N pareillement mais ne sortir que le Kème de N vers stdout
# Messages d'erreur
split-error-suffix-not-parsable = longueur de suffixe invalide : { $value }
split-error-suffix-contains-separator = suffixe invalide { $value }, contient un séparateur de répertoire
split-error-suffix-too-small = la longueur du suffixe doit être au moins { $length }
split-error-multi-character-separator = séparateur multi-caractères { $separator }
split-error-multiple-separator-characters = plusieurs caractères de séparateur spécifiés
split-error-filter-with-kth-chunk = --filter ne traite pas un chunk extrait vers stdout
split-error-invalid-io-block-size = taille de bloc IO invalide : { $size }
split-error-not-supported = --filter n'est actuellement pas supporté sur cette plateforme
split-error-invalid-number-of-chunks = nombre de chunks invalide : { $chunks }
split-error-invalid-chunk-number = numéro de chunk invalide : { $chunk }
split-error-invalid-number-of-lines = nombre de lignes invalide : { $error }
split-error-invalid-number-of-bytes = nombre d'octets invalide : { $error }
split-error-cannot-split-more-than-one-way = impossible de diviser de plus d'une façon
split-error-overflow = Débordement
split-error-output-file-suffixes-exhausted = suffixes de fichiers de sortie épuisés
split-error-numerical-suffix-start-too-large = la valeur de départ du suffixe numérique est trop grande pour la longueur du suffixe
split-error-cannot-open-for-reading = impossible d'ouvrir { $file } en lecture
split-error-would-overwrite-input = { $file } écraserait l'entrée ; abandon
split-error-cannot-determine-input-size = { $input } : impossible de déterminer la taille de l'entrée
split-error-cannot-determine-file-size = { $input } : impossible de déterminer la taille du fichier
split-error-cannot-read-from-input = { $input } : impossible de lire depuis l'entrée : { $error }
split-error-input-output-error = erreur d'entrée/sortie
split-error-unable-to-open-file = impossible d'ouvrir { $file } ; abandon
split-error-unable-to-reopen-file = impossible de rouvrir { $file } ; abandon
split-error-file-descriptor-limit = limite de descripteurs de fichiers atteinte, mais aucun descripteur de fichier à fermer. { $count } écrivains fermés auparavant.
split-error-shell-process-returned = Le processus shell a retourné { $code }
split-error-shell-process-terminated = Le processus shell a été terminé par un signal
# Messages d'aide pour les options de ligne de commande
split-help-bytes = mettre TAILLE octets par fichier de sortie
split-help-line-bytes = mettre au maximum TAILLE octets de lignes par fichier de sortie
split-help-lines = mettre NOMBRE lignes/enregistrements par fichier de sortie
split-help-number = générer CHUNKS fichiers de sortie ; voir l'explication ci-dessous
split-help-additional-suffix = SUFFIXE supplémentaire à ajouter aux noms de fichiers de sortie
split-help-filter = écrire vers la COMMANDE shell ; le nom de fichier est $FILE (Actuellement non implémenté pour Windows)
split-help-elide-empty-files = ne pas générer de fichiers de sortie vides avec '-n'
split-help-numeric-suffixes-short = utiliser des suffixes numériques commençant à 0, pas alphabétiques
split-help-numeric-suffixes = identique à -d, mais permet de définir la valeur de départ
split-help-hex-suffixes-short = utiliser des suffixes hexadécimaux commençant à 0, pas alphabétiques
split-help-hex-suffixes = identique à -x, mais permet de définir la valeur de départ
split-help-suffix-length = générer des suffixes de longueur N (par défaut 2)
split-help-verbose = afficher un diagnostic juste avant l'ouverture de chaque fichier de sortie
split-help-separator = utiliser SEP au lieu de nouvelle ligne comme séparateur d'enregistrement ; '\\0' (zéro) spécifie le caractère NUL

View file

@ -39,10 +39,12 @@ use crate::{
OPT_NUMERIC_SUFFIXES_SHORT, OPT_SUFFIX_LENGTH,
};
use clap::ArgMatches;
use std::collections::HashMap;
use std::path::is_separator;
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
use uucore::locale::{get_message, get_message_with_args};
/// The format to use for suffixes in the filename for each output chunk.
#[derive(Clone, Copy)]
@ -82,15 +84,15 @@ pub struct Suffix {
#[derive(Debug, Error)]
pub enum SuffixError {
/// Invalid suffix length parameter.
#[error("invalid suffix length: {}", .0.quote())]
#[error("{}", get_message_with_args("split-error-suffix-not-parsable", HashMap::from([("value".to_string(), .0.quote().to_string())])))]
NotParsable(String),
/// Suffix contains a directory separator, which is not allowed.
#[error("invalid suffix {}, contains directory separator", .0.quote())]
#[error("{}", get_message_with_args("split-error-suffix-contains-separator", HashMap::from([("value".to_string(), .0.quote().to_string())])))]
ContainsSeparator(String),
/// Suffix is not large enough to split into specified chunks
#[error("the suffix length needs to be at least {0}")]
#[error("{}", get_message_with_args("split-error-suffix-too-small", HashMap::from([("length".to_string(), .0.to_string())])))]
TooSmall(usize),
}
@ -315,7 +317,7 @@ impl<'a> FilenameIterator<'a> {
FixedWidthNumber::new(radix, suffix.length, suffix.start).map_err(|_| {
USimpleError::new(
1,
"numerical suffix start value is too large for the suffix length",
get_message("split-error-numerical-suffix-start-too-large"),
)
})?,
)

View file

@ -16,6 +16,7 @@
//! [positional notation]: https://en.wikipedia.org/wiki/Positional_notation
use std::error::Error;
use std::fmt::{self, Display, Formatter};
use uucore::locale::get_message;
/// An overflow due to incrementing a number beyond its representable limit.
#[derive(Debug)]
@ -23,7 +24,7 @@ pub struct Overflow;
impl Display for Overflow {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "Overflow")
write!(f, "{}", get_message("split-error-overflow"))
}
}

View file

@ -2,6 +2,7 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use std::collections::HashMap;
use std::env;
use std::io::Write;
use std::io::{BufWriter, Error, Result};
@ -10,6 +11,7 @@ use std::process::{Child, Command, Stdio};
use uucore::error::USimpleError;
use uucore::fs;
use uucore::fs::FileInformation;
use uucore::locale::get_message_with_args;
use uucore::show;
/// A writer that writes to a shell_process' stdin
@ -110,11 +112,17 @@ impl Drop for FilterWriter {
if return_code != 0 {
show!(USimpleError::new(
1,
format!("Shell process returned {return_code}")
get_message_with_args(
"split-error-shell-process-returned",
HashMap::from([("code".to_string(), return_code.to_string())])
)
));
}
} else {
show!(USimpleError::new(1, "Shell process terminated by signal"));
show!(USimpleError::new(
1,
get_message_with_args("split-error-shell-process-terminated", HashMap::new())
));
}
}
}
@ -134,14 +142,22 @@ pub fn instantiate_current_writer(
.create(true)
.truncate(true)
.open(Path::new(&filename))
.map_err(|_| Error::other(format!("unable to open '{filename}'; aborting")))?
.map_err(|_| {
Error::other(get_message_with_args(
"split-error-unable-to-open-file",
HashMap::from([("file".to_string(), filename.to_string())]),
))
})?
} else {
// re-open file that we previously created to append to it
std::fs::OpenOptions::new()
.append(true)
.open(Path::new(&filename))
.map_err(|_| {
Error::other(format!("unable to re-open '{filename}'; aborting"))
Error::other(get_message_with_args(
"split-error-unable-to-reopen-file",
HashMap::from([("file".to_string(), filename.to_string())]),
))
})?
};
Ok(BufWriter::new(Box::new(file) as Box<dyn Write>))

View file

@ -2,10 +2,12 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use std::collections::HashMap;
use std::io::Write;
use std::io::{BufWriter, Error, Result};
use std::path::Path;
use uucore::fs;
use uucore::locale::get_message_with_args;
/// Get a file writer
///
@ -23,13 +25,23 @@ pub fn instantiate_current_writer(
.create(true)
.truncate(true)
.open(Path::new(&filename))
.map_err(|_| Error::other(format!("unable to open '{filename}'; aborting")))?
.map_err(|_| {
Error::other(get_message_with_args(
"split-error-unable-to-open-file",
HashMap::from([("file".to_string(), filename.to_string())]),
))
})?
} else {
// re-open file that we previously created to append to it
std::fs::OpenOptions::new()
.append(true)
.open(Path::new(&filename))
.map_err(|_| Error::other(format!("unable to re-open '{filename}'; aborting")))?
.map_err(|_| {
Error::other(get_message_with_args(
"split-error-unable-to-reopen-file",
HashMap::from([("file".to_string(), filename.to_string())]),
))
})?
};
Ok(BufWriter::new(Box::new(file) as Box<dyn Write>))
}

View file

@ -13,6 +13,7 @@ mod strategy;
use crate::filenames::{FilenameIterator, Suffix, SuffixError};
use crate::strategy::{NumberType, Strategy, StrategyError};
use clap::{Arg, ArgAction, ArgMatches, Command, ValueHint, parser::ValueSource};
use std::collections::HashMap;
use std::env;
use std::ffi::OsString;
use std::fs::{File, metadata};
@ -22,10 +23,10 @@ use std::path::Path;
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::{FromIo, UIoError, UResult, USimpleError, UUsageError};
use uucore::locale::{get_message, get_message_with_args};
use uucore::parser::parse_size::parse_size_u64;
use uucore::format_usage;
use uucore::locale::get_message;
use uucore::uio_error;
static OPT_BYTES: &str = "bytes";
@ -237,7 +238,7 @@ pub fn uu_app() -> Command {
.long(OPT_BYTES)
.allow_hyphen_values(true)
.value_name("SIZE")
.help("put SIZE bytes per output file"),
.help(get_message("split-help-bytes")),
)
.arg(
Arg::new(OPT_LINE_BYTES)
@ -245,7 +246,7 @@ pub fn uu_app() -> Command {
.long(OPT_LINE_BYTES)
.allow_hyphen_values(true)
.value_name("SIZE")
.help("put at most SIZE bytes of lines per output file"),
.help(get_message("split-help-line-bytes")),
)
.arg(
Arg::new(OPT_LINES)
@ -254,7 +255,7 @@ pub fn uu_app() -> Command {
.allow_hyphen_values(true)
.value_name("NUMBER")
.default_value("1000")
.help("put NUMBER lines/records per output file"),
.help(get_message("split-help-lines")),
)
.arg(
Arg::new(OPT_NUMBER)
@ -262,7 +263,7 @@ pub fn uu_app() -> Command {
.long(OPT_NUMBER)
.allow_hyphen_values(true)
.value_name("CHUNKS")
.help("generate CHUNKS output files; see explanation below"),
.help(get_message("split-help-number")),
)
// rest of the arguments
.arg(
@ -271,7 +272,7 @@ pub fn uu_app() -> Command {
.allow_hyphen_values(true)
.value_name("SUFFIX")
.default_value("")
.help("additional SUFFIX to append to output file names"),
.help(get_message("split-help-additional-suffix")),
)
.arg(
Arg::new(OPT_FILTER)
@ -279,15 +280,13 @@ pub fn uu_app() -> Command {
.allow_hyphen_values(true)
.value_name("COMMAND")
.value_hint(ValueHint::CommandName)
.help(
"write to shell COMMAND; file name is $FILE (Currently not implemented for Windows)",
),
.help(get_message("split-help-filter")),
)
.arg(
Arg::new(OPT_ELIDE_EMPTY_FILES)
.long(OPT_ELIDE_EMPTY_FILES)
.short('e')
.help("do not generate empty output files with '-n'")
.help(get_message("split-help-elide-empty-files"))
.action(ArgAction::SetTrue),
)
.arg(
@ -298,9 +297,9 @@ pub fn uu_app() -> Command {
OPT_NUMERIC_SUFFIXES,
OPT_NUMERIC_SUFFIXES_SHORT,
OPT_HEX_SUFFIXES,
OPT_HEX_SUFFIXES_SHORT
OPT_HEX_SUFFIXES_SHORT,
])
.help("use numeric suffixes starting at 0, not alphabetic"),
.help(get_message("split-help-numeric-suffixes-short")),
)
.arg(
Arg::new(OPT_NUMERIC_SUFFIXES)
@ -311,10 +310,10 @@ pub fn uu_app() -> Command {
OPT_NUMERIC_SUFFIXES,
OPT_NUMERIC_SUFFIXES_SHORT,
OPT_HEX_SUFFIXES,
OPT_HEX_SUFFIXES_SHORT
OPT_HEX_SUFFIXES_SHORT,
])
.value_name("FROM")
.help("same as -d, but allow setting the start value"),
.help(get_message("split-help-numeric-suffixes")),
)
.arg(
Arg::new(OPT_HEX_SUFFIXES_SHORT)
@ -324,9 +323,9 @@ pub fn uu_app() -> Command {
OPT_NUMERIC_SUFFIXES,
OPT_NUMERIC_SUFFIXES_SHORT,
OPT_HEX_SUFFIXES,
OPT_HEX_SUFFIXES_SHORT
OPT_HEX_SUFFIXES_SHORT,
])
.help("use hex suffixes starting at 0, not alphabetic"),
.help(get_message("split-help-hex-suffixes-short")),
)
.arg(
Arg::new(OPT_HEX_SUFFIXES)
@ -337,10 +336,10 @@ pub fn uu_app() -> Command {
OPT_NUMERIC_SUFFIXES,
OPT_NUMERIC_SUFFIXES_SHORT,
OPT_HEX_SUFFIXES,
OPT_HEX_SUFFIXES_SHORT
OPT_HEX_SUFFIXES_SHORT,
])
.value_name("FROM")
.help("same as -x, but allow setting the start value"),
.help(get_message("split-help-hex-suffixes")),
)
.arg(
Arg::new(OPT_SUFFIX_LENGTH)
@ -348,12 +347,12 @@ pub fn uu_app() -> Command {
.long(OPT_SUFFIX_LENGTH)
.allow_hyphen_values(true)
.value_name("N")
.help("generate suffixes of length N (default 2)"),
.help(get_message("split-help-suffix-length")),
)
.arg(
Arg::new(OPT_VERBOSE)
.long(OPT_VERBOSE)
.help("print a diagnostic just before each output file is opened")
.help(get_message("split-help-verbose"))
.action(ArgAction::SetTrue),
)
.arg(
@ -363,7 +362,7 @@ pub fn uu_app() -> Command {
.allow_hyphen_values(true)
.value_name("SEP")
.action(ArgAction::Append)
.help("use SEP instead of newline as the record separator; '\\0' (zero) specifies the NUL character"),
.help(get_message("split-help-separator")),
)
.arg(
Arg::new(OPT_IO_BLKSIZE)
@ -376,10 +375,7 @@ pub fn uu_app() -> Command {
.default_value("-")
.value_hint(ValueHint::FilePath),
)
.arg(
Arg::new(ARG_PREFIX)
.default_value("x")
)
.arg(Arg::new(ARG_PREFIX).default_value("x"))
}
/// Parameters that control how a file gets split.
@ -420,27 +416,27 @@ enum SettingsError {
Suffix(SuffixError),
/// Multi-character (Invalid) separator
#[error("multi-character separator {}", .0.quote())]
#[error("{}", get_message_with_args("split-error-multi-character-separator", HashMap::from([("separator".to_string(), .0.quote().to_string())])))]
MultiCharacterSeparator(String),
/// Multiple different separator characters
#[error("multiple separator characters specified")]
#[error("{}", get_message("split-error-multiple-separator-characters"))]
MultipleSeparatorCharacters,
/// Using `--filter` with `--number` option sub-strategies that print Kth chunk out of N chunks to stdout
/// K/N
/// l/K/N
/// r/K/N
#[error("--filter does not process a chunk extracted to stdout")]
#[error("{}", get_message("split-error-filter-with-kth-chunk"))]
FilterWithKthChunkNumber,
/// Invalid IO block size
#[error("invalid IO block size: {}", .0.quote())]
#[error("{}", get_message_with_args("split-error-invalid-io-block-size", HashMap::from([("size".to_string(), .0.quote().to_string())])))]
InvalidIOBlockSize(String),
/// The `--filter` option is not supported on Windows.
#[cfg(windows)]
#[error("{OPT_FILTER} is currently not supported in this platform")]
#[error("{}", get_message("split-error-not-supported"))]
NotSupported,
}
@ -532,8 +528,9 @@ impl Settings {
is_new: bool,
) -> io::Result<BufWriter<Box<dyn Write>>> {
if platform::paths_refer_to_same_file(&self.input, filename) {
return Err(io::Error::other(format!(
"'{filename}' would overwrite input; aborting"
return Err(io::Error::other(get_message_with_args(
"split-error-would-overwrite-input",
HashMap::from([("file".to_string(), filename.quote().to_string())]),
)));
}
@ -634,8 +631,9 @@ where
} else if input == "-" {
// STDIN stream that did not fit all content into a buffer
// Most likely continuous/infinite input stream
return Err(io::Error::other(format!(
"{input}: cannot determine input size"
return Err(io::Error::other(get_message_with_args(
"split-error-cannot-determine-input-size",
HashMap::from([("input".to_string(), input.to_string())]),
)));
} else {
// Could be that file size is larger than set read limit
@ -659,8 +657,9 @@ where
// Give up and return an error
// TODO It might be possible to do more here
// to address all possible file types and edge cases
return Err(io::Error::other(format!(
"{input}: cannot determine file size"
return Err(io::Error::other(get_message_with_args(
"split-error-cannot-determine-file-size",
HashMap::from([("input".to_string(), input.to_string())]),
)));
}
}
@ -706,9 +705,9 @@ struct ByteChunkWriter<'a> {
impl<'a> ByteChunkWriter<'a> {
fn new(chunk_size: u64, settings: &'a Settings) -> UResult<Self> {
let mut filename_iterator = FilenameIterator::new(&settings.prefix, &settings.suffix)?;
let filename = filename_iterator
.next()
.ok_or_else(|| USimpleError::new(1, "output file suffixes exhausted"))?;
let filename = filename_iterator.next().ok_or_else(|| {
USimpleError::new(1, get_message("split-error-output-file-suffixes-exhausted"))
})?;
if settings.verbose {
println!("creating file {}", filename.quote());
}
@ -744,10 +743,9 @@ impl Write for ByteChunkWriter<'_> {
self.num_bytes_remaining_in_current_chunk = self.chunk_size;
// Allocate the new file, since at this point we know there are bytes to be written to it.
let filename = self
.filename_iterator
.next()
.ok_or_else(|| io::Error::other("output file suffixes exhausted"))?;
let filename = self.filename_iterator.next().ok_or_else(|| {
io::Error::other(get_message("split-error-output-file-suffixes-exhausted"))
})?;
if self.settings.verbose {
println!("creating file {}", filename.quote());
}
@ -846,9 +844,9 @@ impl<'a> LineChunkWriter<'a> {
settings: &Settings,
filename_iterator: &mut FilenameIterator,
) -> io::Result<BufWriter<Box<dyn Write>>> {
let filename = filename_iterator
.next()
.ok_or_else(|| io::Error::other("output file suffixes exhausted"))?;
let filename = filename_iterator.next().ok_or_else(|| {
io::Error::other(get_message("split-error-output-file-suffixes-exhausted"))
})?;
if settings.verbose {
println!("creating file {}", filename.quote());
}
@ -957,9 +955,9 @@ impl ManageOutFiles for OutFiles {
.map_err(|e| io::Error::other(format!("{e}")))?;
let mut out_files: Self = Self::new();
for _ in 0..num_files {
let filename = filename_iterator
.next()
.ok_or_else(|| USimpleError::new(1, "output file suffixes exhausted"))?;
let filename = filename_iterator.next().ok_or_else(|| {
USimpleError::new(1, get_message("split-error-output-file-suffixes-exhausted"))
})?;
let maybe_writer = if is_writer_optional {
None
} else {
@ -1030,7 +1028,11 @@ impl ManageOutFiles for OutFiles {
// If this fails - give up and propagate the error
uucore::show_error!(
"at file descriptor limit, but no file descriptor left to close. Closed {count} writers before."
"{}",
get_message_with_args(
"split-error-file-descriptor-limit",
HashMap::from([("count".to_string(), count.to_string())])
)
);
return Err(maybe_writer.err().unwrap().into());
}
@ -1169,7 +1171,13 @@ where
Err(error) => {
return Err(USimpleError::new(
1,
format!("{}: cannot read from input : {error}", settings.input),
get_message_with_args(
"split-error-cannot-read-from-input",
HashMap::from([
("input".to_string(), settings.input.clone()),
("error".to_string(), error.to_string()),
]),
),
));
}
}
@ -1476,9 +1484,9 @@ where
let mut line = &line[..];
loop {
if remaining == 0 {
let filename = filename_iterator
.next()
.ok_or_else(|| USimpleError::new(1, "output file suffixes exhausted"))?;
let filename = filename_iterator.next().ok_or_else(|| {
USimpleError::new(1, get_message("split-error-output-file-suffixes-exhausted"))
})?;
if settings.verbose {
println!("creating file {}", filename.quote());
}
@ -1530,8 +1538,12 @@ fn split(settings: &Settings) -> UResult<()> {
let r_box = if settings.input == "-" {
Box::new(stdin()) as Box<dyn Read>
} else {
let r = File::open(Path::new(&settings.input))
.map_err_context(|| format!("cannot open {} for reading", settings.input.quote()))?;
let r = File::open(Path::new(&settings.input)).map_err_context(|| {
get_message_with_args(
"split-error-cannot-open-for-reading",
HashMap::from([("file".to_string(), settings.input.quote().to_string())]),
)
})?;
Box::new(r) as Box<dyn Read>
};
let mut reader = if let Some(c) = settings.io_blksize {
@ -1575,7 +1587,11 @@ fn split(settings: &Settings) -> UResult<()> {
// indicate that. A special error message needs to be
// printed in that case.
ErrorKind::Other => Err(USimpleError::new(1, format!("{e}"))),
_ => Err(uio_error!(e, "input/output error")),
_ => Err(uio_error!(
e,
"{}",
get_message("split-error-input-output-error")
)),
},
}
}
@ -1593,7 +1609,11 @@ fn split(settings: &Settings) -> UResult<()> {
// indicate that. A special error message needs to be
// printed in that case.
ErrorKind::Other => Err(USimpleError::new(1, format!("{e}"))),
_ => Err(uio_error!(e, "input/output error")),
_ => Err(uio_error!(
e,
"{}",
get_message("split-error-input-output-error")
)),
},
}
}

View file

@ -7,9 +7,11 @@
use crate::{OPT_BYTES, OPT_LINE_BYTES, OPT_LINES, OPT_NUMBER};
use clap::{ArgMatches, parser::ValueSource};
use std::collections::HashMap;
use thiserror::Error;
use uucore::{
display::Quotable,
locale::{get_message, get_message_with_args},
parser::parse_size::{ParseSizeError, parse_size_u64, parse_size_u64_max},
};
@ -69,7 +71,7 @@ pub enum NumberTypeError {
/// -n r/N
/// -n r/K/N
/// ```
#[error("invalid number of chunks: {}", .0.quote())]
#[error("{}", get_message_with_args("split-error-invalid-number-of-chunks", HashMap::from([("chunks".to_string(), .0.quote().to_string())])))]
NumberOfChunks(String),
/// The chunk number was invalid.
@ -84,7 +86,7 @@ pub enum NumberTypeError {
/// -n l/K/N
/// -n r/K/N
/// ```
#[error("invalid chunk number: {}", .0.quote())]
#[error("{}", get_message_with_args("split-error-invalid-chunk-number", HashMap::from([("chunk".to_string(), .0.quote().to_string())])))]
ChunkNumber(String),
}
@ -198,11 +200,11 @@ pub enum Strategy {
#[derive(Debug, Error)]
pub enum StrategyError {
/// Invalid number of lines.
#[error("invalid number of lines: {0}")]
#[error("{}", get_message_with_args("split-error-invalid-number-of-lines", HashMap::from([("error".to_string(), .0.to_string())])))]
Lines(ParseSizeError),
/// Invalid number of bytes.
#[error("invalid number of bytes: {0}")]
#[error("{}", get_message_with_args("split-error-invalid-number-of-bytes", HashMap::from([("error".to_string(), .0.to_string())])))]
Bytes(ParseSizeError),
/// Invalid number type.
@ -210,7 +212,7 @@ pub enum StrategyError {
NumberType(NumberTypeError),
/// Multiple chunking strategies were specified (but only one should be).
#[error("cannot split in more than one way")]
#[error("{}", get_message("split-error-cannot-split-more-than-one-way"))]
MultipleWays,
}