mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 21:47:46 +00:00
Implement mv's --strip-trailing-slashes
This commit is contained in:
parent
e7685e6fe9
commit
b8d5602655
1 changed files with 18 additions and 6 deletions
24
src/mv/mv.rs
24
src/mv/mv.rs
|
@ -18,7 +18,7 @@ extern crate libc;
|
||||||
use std::fs::{self, PathExt};
|
use std::fs::{self, PathExt};
|
||||||
use std::io::{BufRead, BufReader, Result, stdin, Write};
|
use std::io::{BufRead, BufReader, Result, stdin, Write};
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -60,9 +60,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
opts.optflag("f", "force", "do not prompt before overwriting");
|
opts.optflag("f", "force", "do not prompt before overwriting");
|
||||||
opts.optflag("i", "interactive", "prompt before override");
|
opts.optflag("i", "interactive", "prompt before override");
|
||||||
opts.optflag("n", "no-clobber", "do not overwrite an existing file");
|
opts.optflag("n", "no-clobber", "do not overwrite an existing file");
|
||||||
// I have yet to find a use-case (and thereby write a test) where this option is useful.
|
opts.optflag("", "strip-trailing-slashes", "remove any trailing slashes from each SOURCE\n \
|
||||||
//opts.optflag("", "strip-trailing-slashes", "remove any trailing slashes from each SOURCE\n \
|
argument");
|
||||||
// argument");
|
|
||||||
opts.optopt("S", "suffix", "override the usual backup suffix", "SUFFIX");
|
opts.optopt("S", "suffix", "override the usual backup suffix", "SUFFIX");
|
||||||
opts.optopt("t", "target-directory", "move all SOURCE arguments into DIRECTORY", "DIRECTORY");
|
opts.optopt("t", "target-directory", "move all SOURCE arguments into DIRECTORY", "DIRECTORY");
|
||||||
opts.optflag("T", "no-target-directory", "treat DEST as a normal file");
|
opts.optflag("T", "no-target-directory", "treat DEST as a normal file");
|
||||||
|
@ -150,8 +149,21 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
verbose: matches.opt_present("v"),
|
verbose: matches.opt_present("v"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let string_to_path = |s: &String| { PathBuf::from(s) };
|
let paths: Vec<PathBuf> = {
|
||||||
let paths: Vec<PathBuf> = matches.free.iter().map(string_to_path).collect();
|
fn string_to_path<'a>(s: &'a String) -> &'a Path {
|
||||||
|
Path::new(s)
|
||||||
|
};
|
||||||
|
fn strip_slashes<'a>(p: &'a Path) -> &'a Path {
|
||||||
|
p.components().as_path()
|
||||||
|
}
|
||||||
|
let to_owned = |p: &Path| p.to_owned();
|
||||||
|
let arguments = matches.free.iter().map(string_to_path);
|
||||||
|
if matches.opt_present("strip-trailing-slashes") {
|
||||||
|
arguments.map(strip_slashes).map(to_owned).collect()
|
||||||
|
} else {
|
||||||
|
arguments.map(to_owned).collect()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
println!("{} {}", NAME, VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue