mirror of
https://git.sr.ht/~nixgoat/vento
synced 2024-11-16 03:53:04 +00:00
item: Implement file dropping
And now you can take files out of your inventory! This should cover most of the functionality.
This commit is contained in:
parent
496bbfb64f
commit
98a93f6d94
21
src/item.rs
21
src/item.rs
|
@ -43,6 +43,23 @@ pub fn take(file: &String) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn drop() {
|
||||
// to be implemented
|
||||
pub fn drop(file: &String, dest: PathBuf) {
|
||||
let ventodir = common::env_config();
|
||||
let active: PathBuf = [ventodir.to_path_buf(), Path::new("active").to_path_buf()].iter().collect();
|
||||
|
||||
let sourcepath: PathBuf = [&active, &Path::new(file).to_path_buf()].iter().collect();
|
||||
let destpath: PathBuf = [Path::new(&dest).to_path_buf(), Path::new(file).to_path_buf()].iter().collect();
|
||||
|
||||
if Path::exists(&destpath) {
|
||||
println!("❌ {}", format!("A file with the same name already exists in the destination! Try renaming it or dropping this file somewhere else.").red());
|
||||
} else if sourcepath.is_file() | sourcepath.is_symlink() {
|
||||
fs::copy(&sourcepath, &destpath).expect("❌ Vento was unable to copy the file.");
|
||||
fs::remove_file(&sourcepath).expect("❌ Vento was unable to remove the file.");
|
||||
} else if sourcepath.is_dir() {
|
||||
let destpath: PathBuf = Path::new(&dest).to_path_buf();
|
||||
let options = CopyOptions::new();
|
||||
move_dir(&sourcepath, &destpath, &options).expect("❌ Vento was unable to move the directory.");
|
||||
} else {
|
||||
println!("❌ {}", format!("No such file or directory.").red());
|
||||
}
|
||||
}
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
|
||||
use std::env;
|
||||
use std::process;
|
||||
use std::path::{Path, PathBuf};
|
||||
use colored::Colorize;
|
||||
|
||||
mod inv;
|
||||
|
@ -44,7 +46,22 @@ fn main() {
|
|||
} else {
|
||||
println!("❌ {}", format!("You need to specify a file.").red())
|
||||
};
|
||||
}
|
||||
},
|
||||
"drop" => {
|
||||
if args.len() == 3 {
|
||||
item::drop(&args[2], match env::current_dir() {
|
||||
Ok(dir) => dir,
|
||||
Err(_) => {
|
||||
println!("❌ {}", format!("Vento was unable to detect your current directory. Have you configured your environment correctly?").red());
|
||||
process::exit(1);
|
||||
}
|
||||
});
|
||||
} else if args.len() == 4 {
|
||||
item::drop(&args[2], Path::new(&args[3]).to_path_buf());
|
||||
} else {
|
||||
println!("❌ {}", format!("You need to specify a file.").red())
|
||||
};
|
||||
},
|
||||
_ => println!("❔ Command not found. Type \"vento help\" to see all commands available.")
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue