inv: Add "message" arg to slot switching

When undoing a slot switching command, it would show the message
normally show when running the command by itself, which is not supposed
to happen. This commit fixes that by adding a boolean argument that will
print the message when true.
This commit is contained in:
Lux Aliaga 2022-11-03 19:42:39 -03:00
parent c1533e6b41
commit 19aa1955c8
Signed by: lux
GPG Key ID: B56C805968637437
3 changed files with 10 additions and 7 deletions

View File

@ -38,7 +38,7 @@ fn main() -> Result<()> {
match args[1].as_str() {
"-h" | "--help" => help::vento()?,
"-i" | "--init" => inv::init()?,
"-c" | "--switch" => inv::switch()?,
"-c" | "--switch" => inv::switch(true)?,
"-u" | "--undo" => history::undo()?,
"-s" => match args.len() {
4 => inv::list(&args[2], &args[3])?,

View File

@ -16,7 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use crate::common;
use crate::{common, inv, item};
use anyhow::{bail, Result};
use colored::Colorize;
use std::fs;
@ -46,14 +47,14 @@ pub fn undo() -> Result<()> {
match contents[3] {
"take" => {
let destpath = Path::new(contents[0]).to_path_buf();
crate::item::drop(&String::from(contents[1]), contents[2], destpath, false)?;
item::drop(&String::from(contents[1]), contents[2], destpath, false)?;
}
"drop" => {
let path = vec![contents[0], contents[1]].join("/");
crate::item::take(&path, contents[2], false)?;
item::take(&path, contents[2], false)?;
}
"switch" => {
crate::inv::switch()?;
inv::switch(false)?;
}
_ => bail!("Illegal action".red()),
}

View File

@ -165,7 +165,7 @@ pub fn list(slot: &str, dir: &str) -> Result<()> {
}
/// Switches inevntory slots between each other, making the currently active inventory inactive and viceversa
pub fn switch() -> Result<()> {
pub fn switch(message: bool) -> Result<()> {
let ventodir = &common::env_config()?.vento_dir;
let active = &common::env_config()?.active_dir;
let inactive = &common::env_config()?.inactive_dir;
@ -186,7 +186,9 @@ pub fn switch() -> Result<()> {
action: common::Action::Switch,
})?;
println!("🎉 {}", "Switched inventory slots!".green());
if message {
println!("🎉 {}", "Switched inventory slots!".green());
}
Ok(())
}