mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 14:52:41 +00:00
Merge pull request #5987 from tertsdiepraam/expand-remove-collect-ignore
`expand`: do not ignore invalid UTF-8
This commit is contained in:
commit
9866f022a8
1 changed files with 12 additions and 11 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
|
||||
use std::error::Error;
|
||||
use std::ffi::OsString;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
||||
|
@ -243,18 +244,20 @@ impl Options {
|
|||
|
||||
/// Preprocess command line arguments and expand shortcuts. For example, "-7" is expanded to
|
||||
/// "--tabs=7" and "-1,3" to "--tabs=1 --tabs=3".
|
||||
fn expand_shortcuts(args: &[String]) -> Vec<String> {
|
||||
fn expand_shortcuts(args: Vec<OsString>) -> Vec<OsString> {
|
||||
let mut processed_args = Vec::with_capacity(args.len());
|
||||
|
||||
for arg in args {
|
||||
if arg.starts_with('-') && arg[1..].chars().all(is_digit_or_comma) {
|
||||
arg[1..]
|
||||
.split(',')
|
||||
.filter(|s| !s.is_empty())
|
||||
.for_each(|s| processed_args.push(format!("--tabs={s}")));
|
||||
} else {
|
||||
processed_args.push(arg.to_string());
|
||||
if let Some(arg) = arg.to_str() {
|
||||
if arg.starts_with('-') && arg[1..].chars().all(is_digit_or_comma) {
|
||||
arg[1..]
|
||||
.split(',')
|
||||
.filter(|s| !s.is_empty())
|
||||
.for_each(|s| processed_args.push(OsString::from(format!("--tabs={s}"))));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
processed_args.push(arg);
|
||||
}
|
||||
|
||||
processed_args
|
||||
|
@ -262,9 +265,7 @@ fn expand_shortcuts(args: &[String]) -> Vec<String> {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().try_get_matches_from(expand_shortcuts(&args))?;
|
||||
let matches = uu_app().try_get_matches_from(expand_shortcuts(args.collect()))?;
|
||||
|
||||
expand(&Options::new(&matches)?)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue