Merge pull request #3832 from tertsdiepraam/simplify-encoding-handling

Simplify invalid encoding handling
This commit is contained in:
Sylvestre Ledru
2022-08-17 18:59:59 +02:00
committed by GitHub
48 changed files with 104 additions and 298 deletions
+2 -4
View File
@@ -12,7 +12,7 @@ use std::io::{stdout, Read, Write};
use uucore::display::Quotable;
use uucore::encoding::{wrap_print, Data, Format};
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
use std::fs::File;
use std::io::{BufReader, Stdin};
@@ -87,9 +87,7 @@ impl Config {
pub fn parse_base_cmd_args(args: impl uucore::Args, about: &str, usage: &str) -> UResult<Config> {
let command = base_app(about, usage);
let arg_list = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let arg_list = args.collect_lossy();
Config::from(&command.try_get_matches_from(arg_list)?)
}
+2 -4
View File
@@ -11,7 +11,7 @@ use clap::{crate_version, Arg, Command};
use std::path::{is_separator, PathBuf};
use uucore::display::Quotable;
use uucore::error::{UResult, UUsageError};
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
static ABOUT: &str = r#"Print NAME with any leading directory components removed
If specified, also remove a trailing SUFFIX"#;
@@ -28,9 +28,7 @@ pub mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let args = args.collect_lossy();
// Since options have to go before names,
// if the first argument is not an option, then there is no option,
+1 -5
View File
@@ -14,7 +14,6 @@ use uu_base32::base_common::{self, Config, BASE_CMD_PARSE_ERROR};
use uucore::{
encoding::Format,
error::{UResult, UUsageError},
InvalidEncodingHandling,
};
use std::io::{stdin, Read};
@@ -52,10 +51,7 @@ pub fn uu_app<'a>() -> Command<'a> {
fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> {
let matches = uu_app()
.try_get_matches_from(
args.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(),
)
.try_get_matches_from(args.collect_lossy())
.with_exit_code(1)?;
let format = ENCODINGS
.iter()
+2 -4
View File
@@ -36,7 +36,7 @@ use std::net::Shutdown;
use std::os::unix::fs::FileTypeExt;
#[cfg(unix)]
use unix_socket::UnixStream;
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
static NAME: &str = "cat";
static USAGE: &str = "{} [OPTION]... [FILE]...";
@@ -184,9 +184,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
let args = args.collect_ignore();
let matches = uu_app().try_get_matches_from(args)?;
+2 -4
View File
@@ -18,7 +18,7 @@ use uucore::fs::is_symlink;
use uucore::libc::mode_t;
#[cfg(not(windows))]
use uucore::mode;
use uucore::{format_usage, show_error, InvalidEncodingHandling};
use uucore::{format_usage, show_error};
static ABOUT: &str = "Change the mode of each FILE to MODE.
With --reference, change the mode of each FILE to that of RFILE.";
@@ -46,9 +46,7 @@ fn get_long_usage() -> String {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut args = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let mut args = args.collect_lossy();
// Before we can parse 'args' with clap (and previously getopts),
// a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE").
+2 -4
View File
@@ -17,7 +17,7 @@ use std::path::Path;
use std::process;
use uucore::error::{set_exit_code, UResult};
use uucore::libc::{self, chroot, setgid, setgroups, setuid};
use uucore::{entries, format_usage, InvalidEncodingHandling};
use uucore::{entries, format_usage};
static ABOUT: &str = "Run COMMAND with root directory set to NEWROOT.";
static USAGE: &str = "{} [OPTION]... NEWROOT [COMMAND [ARG]...]";
@@ -33,9 +33,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
+1 -4
View File
@@ -12,7 +12,6 @@ use std::io::{self, stdin, BufReader, Read};
use std::path::Path;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult};
use uucore::InvalidEncodingHandling;
use uucore::{format_usage, show};
// NOTE: CRC_TABLE_LEN *must* be <= 256 as we cast 0..CRC_TABLE_LEN to u8
@@ -114,9 +113,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(args);
+2 -4
View File
@@ -13,7 +13,7 @@ use std::io::{self, stdin, BufRead, BufReader, Stdin};
use std::path::Path;
use uucore::error::FromIo;
use uucore::error::UResult;
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
use clap::{crate_version, Arg, ArgMatches, Command};
@@ -132,9 +132,7 @@ fn open_file(name: &str) -> io::Result<LineReader> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let filename1 = matches.value_of(options::FILE_1).unwrap();
+2 -4
View File
@@ -16,7 +16,7 @@ use clap::{crate_version, Arg, ArgMatches, Command};
use regex::Regex;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult};
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
mod csplit_error;
mod patterns;
@@ -713,9 +713,7 @@ mod tests {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(args);
+2 -4
View File
@@ -19,8 +19,8 @@ use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use self::searcher::Searcher;
use uucore::format_usage;
use uucore::ranges::Range;
use uucore::{format_usage, InvalidEncodingHandling};
mod searcher;
@@ -398,9 +398,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
let args = args.collect_ignore();
let delimiter_is_equal = args.contains(&"-d=".to_string()); // special case
let matches = uu_app().get_matches_from(args);
+2 -3
View File
@@ -37,7 +37,7 @@ use clap::{crate_version, Arg, ArgMatches, Command};
use gcd::Gcd;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult};
use uucore::{show_error, InvalidEncodingHandling};
use uucore::show_error;
const ABOUT: &str = "copy, and optionally convert, a file system resource";
const BUF_INIT_BYTE: u8 = 0xDD;
@@ -706,8 +706,7 @@ fn append_dashes_if_not_present(mut acc: Vec<String>, mut s: String) -> Vec<Stri
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let dashed_args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any()
.collect_ignore()
.into_iter()
.fold(Vec::new(), append_dashes_if_not_present);
+2 -4
View File
@@ -65,9 +65,7 @@ pub fn guess_syntax() -> OutputFmt {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(&args);
@@ -278,7 +276,7 @@ enum ParseState {
}
use std::collections::HashMap;
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
fn parse<T>(lines: T, fmt: &OutputFmt, fp: &str) -> Result<String, String>
where
+2 -4
View File
@@ -9,7 +9,7 @@ use clap::{crate_version, Arg, Command};
use std::path::Path;
use uucore::display::print_verbatim;
use uucore::error::{UResult, UUsageError};
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
static ABOUT: &str = "strip last component from file name";
const USAGE: &str = "{} [OPTION] NAME...";
@@ -28,9 +28,7 @@ fn get_long_usage() -> String {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let args = args.collect_lossy();
let after_help = get_long_usage();
+1 -4
View File
@@ -39,7 +39,6 @@ use uucore::error::{UError, UResult};
use uucore::format_usage;
use uucore::parse_glob;
use uucore::parse_size::{parse_size, ParseSizeError};
use uucore::InvalidEncodingHandling;
#[cfg(windows)]
use winapi::shared::minwindef::{DWORD, LPVOID};
#[cfg(windows)]
@@ -516,9 +515,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult<Vec<Pattern>> {
#[uucore::main]
#[allow(clippy::cognitive_complexity)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(args);
+2 -4
View File
@@ -11,7 +11,7 @@ use std::io::{self, Write};
use std::iter::Peekable;
use std::str::Chars;
use uucore::error::{FromIo, UResult};
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
const NAME: &str = "echo";
const ABOUT: &str = "display a line of text";
@@ -110,9 +110,7 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result<bool> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let no_newline = matches.contains_id(options::NO_NEWLINE);
+2 -4
View File
@@ -22,7 +22,7 @@ use std::str::from_utf8;
use unicode_width::UnicodeWidthChar;
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult};
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
static ABOUT: &str = "Convert tabs in each FILE to spaces, writing to standard output.
With no FILE, or when FILE is -, read standard input.";
@@ -269,9 +269,7 @@ fn expand_shortcuts(args: &[String]) -> Vec<String> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(expand_shortcuts(&args));
+1 -4
View File
@@ -7,7 +7,6 @@
use clap::{crate_version, Arg, Command};
use uucore::error::{UResult, USimpleError};
use uucore::InvalidEncodingHandling;
mod syntax_tree;
mod tokens;
@@ -33,9 +32,7 @@ pub fn uu_app<'a>() -> Command<'a> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let args = args.collect_lossy();
// For expr utility we do not want getopts.
// The following usage should work without escaping hyphens: `expr -15 = 1 + 2 \* \( 3 - -4 \)`
+2 -4
View File
@@ -13,7 +13,7 @@ use std::io::{stdin, BufRead, BufReader, Read};
use std::path::Path;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::{format_usage, InvalidEncodingHandling};
use uucore::format_usage;
const TAB_WIDTH: usize = 8;
@@ -31,9 +31,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let args = args.collect_lossy();
let (args, obs_width) = handle_obsolete(&args[..]);
let matches = uu_app().get_matches_from(args);
+2 -4
View File
@@ -16,8 +16,8 @@ use nix::unistd::Pid;
use std::io::Error;
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, USimpleError};
use uucore::format_usage;
use uucore::signals::{signal_by_name_or_value, ALL_SIGNALS};
use uucore::{format_usage, InvalidEncodingHandling};
static ABOUT: &str = "Send signal to processes or list information about signals.";
const USAGE: &str = "{} [OPTIONS]... PID...";
@@ -38,9 +38,7 @@ pub enum Mode {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
let mut args = args.collect_ignore();
let obs_signal = handle_obsolete(&mut args);
let matches = uu_app().get_matches_from(args);
+1 -4
View File
@@ -15,7 +15,6 @@ extern crate uucore;
use clap::{crate_version, Command};
use std::ffi::CStr;
use uucore::error::UResult;
use uucore::InvalidEncodingHandling;
extern "C" {
// POSIX requires using getlogin (or equivalent code)
@@ -37,9 +36,7 @@ static ABOUT: &str = "Print user's login name";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args
.collect_str(InvalidEncodingHandling::Ignore)
.accept_any();
let args = args.collect_ignore();
let _ = uu_app().get_matches_from(args);

Some files were not shown because too many files have changed in this diff Show More