mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
base32, base64, basenc: Simplifying the base encoding uu_app and adding basic buffer tests (#9409)
* Simplifying the base encoding uu_app and adding basic buffer tests * Added an ignore for the spell checker on base encoding output
This commit is contained in:
@@ -10,20 +10,11 @@ use uucore::{encoding::Format, error::UResult, translate};
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let format = Format::Base32;
|
||||
let (about, usage) = get_info();
|
||||
let config = base_common::parse_base_cmd_args(args, about, usage)?;
|
||||
let config = base_common::parse_base_cmd_args(args, uu_app())?;
|
||||
let mut input = base_common::get_input(&config)?;
|
||||
base_common::handle_input(&mut input, format, config)
|
||||
base_common::handle_input(&mut input, Format::Base32, config)
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
let (about, usage) = get_info();
|
||||
base_common::base_app(about, usage)
|
||||
}
|
||||
|
||||
fn get_info() -> (&'static str, &'static str) {
|
||||
let about: &'static str = Box::leak(translate!("base32-about").into_boxed_str());
|
||||
let usage: &'static str = Box::leak(translate!("base32-usage").into_boxed_str());
|
||||
(about, usage)
|
||||
base_common::base_app(translate!("base32-about"), translate!("base32-usage"))
|
||||
}
|
||||
|
||||
@@ -97,21 +97,16 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_base_cmd_args(
|
||||
args: impl uucore::Args,
|
||||
about: &'static str,
|
||||
usage: &str,
|
||||
) -> UResult<Config> {
|
||||
let command = base_app(about, usage);
|
||||
pub fn parse_base_cmd_args(args: impl uucore::Args, command: Command) -> UResult<Config> {
|
||||
let matches = uucore::clap_localization::handle_clap_result(command, args)?;
|
||||
Config::from(&matches)
|
||||
}
|
||||
|
||||
pub fn base_app(about: &'static str, usage: &str) -> Command {
|
||||
pub fn base_app(about: String, usage: String) -> Command {
|
||||
let cmd = Command::new(uucore::util_name())
|
||||
.version(uucore::crate_version!())
|
||||
.about(about)
|
||||
.override_usage(format_usage(usage))
|
||||
.override_usage(format_usage(&usage))
|
||||
.infer_long_args(true);
|
||||
uucore::clap_localization::configure_localized_command(cmd)
|
||||
// Format arguments.
|
||||
|
||||
@@ -10,20 +10,11 @@ use uucore::{encoding::Format, error::UResult};
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let format = Format::Base64;
|
||||
let (about, usage) = get_info();
|
||||
let config = base_common::parse_base_cmd_args(args, about, usage)?;
|
||||
let config = base_common::parse_base_cmd_args(args, uu_app())?;
|
||||
let mut input = base_common::get_input(&config)?;
|
||||
base_common::handle_input(&mut input, format, config)
|
||||
base_common::handle_input(&mut input, Format::Base64, config)
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
let (about, usage) = get_info();
|
||||
base_common::base_app(about, usage)
|
||||
}
|
||||
|
||||
fn get_info() -> (&'static str, &'static str) {
|
||||
let about: &'static str = Box::leak(translate!("base64-about").into_boxed_str());
|
||||
let usage: &'static str = Box::leak(translate!("base64-usage").into_boxed_str());
|
||||
(about, usage)
|
||||
base_common::base_app(translate!("base64-about"), translate!("base64-usage"))
|
||||
}
|
||||
|
||||
@@ -44,11 +44,8 @@ fn get_encodings() -> Vec<(&'static str, Format, String)> {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
let about: &'static str = Box::leak(translate!("basenc-about").into_boxed_str());
|
||||
let usage: &'static str = Box::leak(translate!("basenc-usage").into_boxed_str());
|
||||
|
||||
let encodings = get_encodings();
|
||||
let mut command = base_common::base_app(about, usage);
|
||||
let mut command = base_common::base_app(translate!("basenc-about"), translate!("basenc-usage"));
|
||||
|
||||
for encoding in &encodings {
|
||||
let raw_arg = Arg::new(encoding.0)
|
||||
|
||||
@@ -150,3 +150,12 @@ fn test_base32_file_not_found() {
|
||||
.fails()
|
||||
.stderr_only("base32: a.txt: No such file or directory\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encode_large_input_is_buffered() {
|
||||
let input = "A".repeat(6000);
|
||||
new_ucmd!()
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_contains("BIFAUCQK"); // spell-checker:disable-line
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user