mirror of
https://github.com/nivekuil/rip
synced 2025-02-17 04:28:26 +00:00
Add --decompose flag
This commit is contained in:
parent
64d2ff7521
commit
e6daa3b532
1 changed files with 23 additions and 12 deletions
21
src/main.rs
21
src/main.rs
|
@ -21,22 +21,33 @@ Send files to the graveyard (/tmp/.graveyard) instead of unlinking them.")
|
|||
.help("File or directory to remove")
|
||||
.required(true)
|
||||
.multiple(true)
|
||||
.index(1))
|
||||
.index(1)
|
||||
.conflicts_with("decompose"))
|
||||
.arg(Arg::with_name("graveyard")
|
||||
.help("Directory where deleted files go to rest")
|
||||
.long("graveyard")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("decompose")
|
||||
.help("Permanently delete (unlink) the entire graveyard")
|
||||
.long("decompose"))
|
||||
.get_matches();
|
||||
|
||||
let graveyard: &Path = Path::new(matches.value_of("graveyard")
|
||||
.unwrap_or(GRAVEYARD));
|
||||
let sources: clap::Values = matches.values_of("SOURCE").unwrap();
|
||||
let cwd: PathBuf = current_dir().expect("Error getting current directory");
|
||||
if cwd.starts_with(graveyard) {
|
||||
println!("You should use rm to delete files in the graveyard.");
|
||||
|
||||
if matches.is_present("decompose") {
|
||||
fs::remove_dir_all(graveyard).expect("Failed to delete graveyard");
|
||||
return;
|
||||
}
|
||||
|
||||
let cwd: PathBuf = current_dir().expect("Error getting current directory");
|
||||
if cwd.starts_with(graveyard) {
|
||||
println!("You should use rm to delete files in the graveyard, \
|
||||
or --decompose to delete everything at once.");
|
||||
return;
|
||||
}
|
||||
|
||||
let sources: clap::Values = matches.values_of("SOURCE").unwrap();
|
||||
for source in sources {
|
||||
if let Err(e) = bury(source, &cwd, graveyard) {
|
||||
println!("ERROR: {}: {}", e, source);
|
||||
|
|
Loading…
Add table
Reference in a new issue