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
15 changes: 15 additions & 0 deletions src/uu/basenc/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ basenc-about = Encode/decode data and print to standard output
the formal alphabet. Use --ignore-garbage to attempt to recover
from any other non-alphabet bytes in the encoded stream.
basenc-usage = basenc [OPTION]... [FILE]

# Help messages for encoding formats
basenc-help-base64 = same as 'base64' program
basenc-help-base64url = file- and url-safe base64
basenc-help-base32 = same as 'base32' program
basenc-help-base32hex = extended hex alphabet base32
basenc-help-base16 = hex encoding
basenc-help-base2lsbf = bit string with least significant bit (lsb) first
basenc-help-base2msbf = bit string with most significant bit (msb) first
basenc-help-z85 = ascii85-like encoding;
when encoding, input length must be a multiple of 4;
when decoding, input length must be a multiple of 5

# Error messages
basenc-error-missing-encoding-type = missing encoding type
22 changes: 22 additions & 0 deletions src/uu/basenc/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
basenc-about = Encoder/décoder des données et afficher vers la sortie standard
Sans FICHIER, ou lorsque FICHIER est -, lire l'entrée standard.

Lors du décodage, l'entrée peut contenir des nouvelles lignes en plus des octets de
l'alphabet formel. Utilisez --ignore-garbage pour tenter de récupérer
depuis tout autre octet non-alphabétique dans le flux encodé.
basenc-usage = basenc [OPTION]... [FICHIER]

# Messages d'aide pour les formats d'encodage
basenc-help-base64 = identique au programme 'base64'
basenc-help-base64url = base64 sécurisé pour fichiers et URLs
basenc-help-base32 = identique au programme 'base32'
basenc-help-base32hex = base32 avec alphabet hexadécimal étendu
basenc-help-base16 = encodage hexadécimal
basenc-help-base2lsbf = chaîne de bits avec le bit de poids faible (lsb) en premier
basenc-help-base2msbf = chaîne de bits avec le bit de poids fort (msb) en premier
basenc-help-z85 = encodage de type ascii85 ;
lors de l'encodage, la longueur d'entrée doit être un multiple de 4 ;
lors du décodage, la longueur d'entrée doit être un multiple de 5

# Messages d'erreur
basenc-error-missing-encoding-type = type d'encodage manquant
76 changes: 43 additions & 33 deletions src/uu/basenc/src/basenc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,49 @@
encoding::Format,
error::{UResult, UUsageError},
};
const ENCODINGS: &[(&str, Format, &str)] = &[
("base64", Format::Base64, "same as 'base64' program"),
("base64url", Format::Base64Url, "file- and url-safe base64"),
("base32", Format::Base32, "same as 'base32' program"),
(
"base32hex",
Format::Base32Hex,
"extended hex alphabet base32",
),
("base16", Format::Base16, "hex encoding"),
(
"base2lsbf",
Format::Base2Lsbf,
"bit string with least significant bit (lsb) first",
),
(
"base2msbf",
Format::Base2Msbf,
"bit string with most significant bit (msb) first",
),
(
"z85",
Format::Z85,
"ascii85-like encoding;\n\
when encoding, input length must be a multiple of 4;\n\
when decoding, input length must be a multiple of 5",
),
];

fn get_encodings() -> Vec<(&'static str, Format, String)> {
vec![
("base64", Format::Base64, get_message("basenc-help-base64")),
(
"base64url",
Format::Base64Url,
get_message("basenc-help-base64url"),
),
("base32", Format::Base32, get_message("basenc-help-base32")),
(
"base32hex",
Format::Base32Hex,
get_message("basenc-help-base32hex"),
),
("base16", Format::Base16, get_message("basenc-help-base16")),
(
"base2lsbf",
Format::Base2Lsbf,
get_message("basenc-help-base2lsbf"),
),
(
"base2msbf",
Format::Base2Msbf,
get_message("basenc-help-base2msbf"),
),
("z85", Format::Z85, get_message("basenc-help-z85")),
]
}

pub fn uu_app() -> Command {
let about: &'static str = Box::leak(get_message("basenc-about").into_boxed_str());
let usage: &'static str = Box::leak(get_message("basenc-usage").into_boxed_str());

let encodings = get_encodings();
let mut command = base_common::base_app(about, usage);
for encoding in ENCODINGS {

for encoding in &encodings {
let raw_arg = Arg::new(encoding.0)
.long(encoding.0)
.help(encoding.2)
.help(&encoding.2)
.action(ArgAction::SetTrue);
let overriding_arg = ENCODINGS
let overriding_arg = encodings
.iter()
.fold(raw_arg, |arg, enc| arg.overrides_with(enc.0));
command = command.arg(overriding_arg);
Expand All @@ -64,10 +67,17 @@
let matches = uu_app()
.try_get_matches_from(args.collect_lossy())
.with_exit_code(1)?;
let format = ENCODINGS

let encodings = get_encodings();
let format = encodings
.iter()
.find(|encoding| matches.get_flag(encoding.0))
.ok_or_else(|| UUsageError::new(BASE_CMD_PARSE_ERROR, "missing encoding type"))?
.ok_or_else(|| {
UUsageError::new(
BASE_CMD_PARSE_ERROR,
get_message("basenc-error-missing-encoding-type"),
)
})?

Check warning on line 80 in src/uu/basenc/src/basenc.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/basenc/src/basenc.rs#L76-L80

Added lines #L76 - L80 were not covered by tests
.1;
let config = Config::from(&matches)?;
Ok((config, format))
Expand Down
Loading