mirror of https://git.sr.ht/~nixgoat/vento
item: Implement taking files
You can now take files and put them in your inventory! An essential function of this program that should've been implemented from the beginning!
This commit is contained in:
parent
8a68b7d3b5
commit
a3894ab02a
|
@ -56,6 +56,12 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fs_extra"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.7"
|
||||
|
@ -169,6 +175,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"colored",
|
||||
"dirs",
|
||||
"fs_extra",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -8,3 +8,4 @@ edition = "2021"
|
|||
[dependencies]
|
||||
dirs = "4.0.0"
|
||||
colored = "2.0.0"
|
||||
fs_extra = "1.2.0"
|
||||
|
|
26
src/item.rs
26
src/item.rs
|
@ -17,8 +17,30 @@
|
|||
*
|
||||
*/
|
||||
|
||||
pub fn take() {
|
||||
// to be implemented
|
||||
use std::fs;
|
||||
use fs_extra::dir::{CopyOptions, move_dir};
|
||||
use std::path::{Path, PathBuf};
|
||||
use colored::Colorize;
|
||||
use super::common;
|
||||
|
||||
pub fn take(file: &String) {
|
||||
let ventodir = common::env_config();
|
||||
let active: PathBuf = [ventodir.to_path_buf(), Path::new("active").to_path_buf()].iter().collect();
|
||||
|
||||
let sourcepath: PathBuf = Path::new(&file).to_path_buf();
|
||||
let destpath: PathBuf = [&active, &Path::new(file).to_path_buf()].iter().collect();
|
||||
|
||||
if Path::exists(&sourcepath) {
|
||||
println!("❌ {}", format!("A file with the same name already exists in your inventory!").red());
|
||||
} else if sourcepath.is_file() | sourcepath.is_symlink() {
|
||||
fs::copy(&file, &destpath).expect("❌ Vento was unable to copy the file.");
|
||||
fs::remove_file(&file).expect("❌ Vento was unable to remove the file.");
|
||||
} else if sourcepath.is_dir() {
|
||||
let options = CopyOptions::new();
|
||||
move_dir(&file, &active, &options).expect("❌ Vento was unable to move the directory.");
|
||||
} else {
|
||||
println!("❌ {}", format!("No such file or directory.").red());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drop() {
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -21,6 +21,7 @@ use std::env;
|
|||
use colored::Colorize;
|
||||
|
||||
mod inv;
|
||||
mod item;
|
||||
mod common;
|
||||
|
||||
fn main() {
|
||||
|
@ -37,6 +38,13 @@ fn main() {
|
|||
};
|
||||
},
|
||||
"switch" => inv::switch(),
|
||||
"take" => {
|
||||
if args.len() == 3 {
|
||||
item::take(&args[2]);
|
||||
} else {
|
||||
println!("❌ {}", format!("You need to specify a file.").red())
|
||||
};
|
||||
}
|
||||
_ => println!("❔ Command not found. Type \"vento help\" to see all commands available.")
|
||||
}
|
||||
} else {
|
||||
|
@ -49,14 +57,16 @@ fn help() {
|
|||
© 2022 Lux Aliaga. Licensed under GPLv3
|
||||
|
||||
{}
|
||||
- {}: Initializes Vento
|
||||
- {}: Takes a file or directory and saves it in your inventory
|
||||
- {}: Lists files in selected inventory
|
||||
- {}: Switches slots
|
||||
- {}: Initializes Vento
|
||||
- {}: Displays this message",
|
||||
format!("Vento").bold().blue(),
|
||||
format!("Usage:").bold(),
|
||||
format!("init").bold().green(),
|
||||
format!("take [file | directory]").bold().green(),
|
||||
format!("list [slot]").bold().green(),
|
||||
format!("switch").bold().green(),
|
||||
format!("init").bold().green(),
|
||||
format!("help").bold().green());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue