mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +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 clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::ffi::OsString;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
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
|
/// Preprocess command line arguments and expand shortcuts. For example, "-7" is expanded to
|
||||||
/// "--tabs=7" and "-1,3" to "--tabs=1 --tabs=3".
|
/// "--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());
|
let mut processed_args = Vec::with_capacity(args.len());
|
||||||
|
|
||||||
for arg in args {
|
for arg in args {
|
||||||
if arg.starts_with('-') && arg[1..].chars().all(is_digit_or_comma) {
|
if let Some(arg) = arg.to_str() {
|
||||||
arg[1..]
|
if arg.starts_with('-') && arg[1..].chars().all(is_digit_or_comma) {
|
||||||
.split(',')
|
arg[1..]
|
||||||
.filter(|s| !s.is_empty())
|
.split(',')
|
||||||
.for_each(|s| processed_args.push(format!("--tabs={s}")));
|
.filter(|s| !s.is_empty())
|
||||||
} else {
|
.for_each(|s| processed_args.push(OsString::from(format!("--tabs={s}"))));
|
||||||
processed_args.push(arg.to_string());
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
processed_args.push(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
processed_args
|
processed_args
|
||||||
|
@ -262,9 +265,7 @@ fn expand_shortcuts(args: &[String]) -> Vec<String> {
|
||||||
|
|
||||||
#[uucore::main]
|
#[uucore::main]
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let args = args.collect_ignore();
|
let matches = uu_app().try_get_matches_from(expand_shortcuts(args.collect()))?;
|
||||||
|
|
||||||
let matches = uu_app().try_get_matches_from(expand_shortcuts(&args))?;
|
|
||||||
|
|
||||||
expand(&Options::new(&matches)?)
|
expand(&Options::new(&matches)?)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue