cat(1): better argv0 parsing
This commit is contained in:
parent
eb0ae4665f
commit
c33d9e0556
10
src/cat.rs
10
src/cat.rs
@ -29,6 +29,8 @@ use sysexits::ExitCode;
|
|||||||
|
|
||||||
#[derive(Args, Debug)]
|
#[derive(Args, Debug)]
|
||||||
struct Arguments {
|
struct Arguments {
|
||||||
|
argv0: String,
|
||||||
|
|
||||||
#[arg(short = "u")]
|
#[arg(short = "u")]
|
||||||
u: bool,
|
u: bool,
|
||||||
|
|
||||||
@ -36,15 +38,15 @@ struct Arguments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let mut arguments = env::args().collect::<Vec<String>>();
|
let mut args = Arguments::from_args(env::args()
|
||||||
let argv0 = arguments.remove(0);
|
.collect::<Vec<String>>()
|
||||||
|
|
||||||
let mut args = Arguments::from_args(arguments
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(String::as_str)
|
.map(String::as_str)
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
|
let argv0 = args.argv0;
|
||||||
|
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
if args.paths.is_empty() { args.paths.push("-".to_string()); }
|
if args.paths.is_empty() { args.paths.push("-".to_string()); }
|
||||||
|
Reference in New Issue
Block a user