From de70fedbdf1f380deaaa294f50302348aa9c4184 Mon Sep 17 00:00:00 2001 From: Mystikfluu Date: Tue, 27 Dec 2022 22:30:30 +0100 Subject: [PATCH] fix bugs & add more help messages Co-authored-by: Alpisc --- VERSION_INFO.md | 7 +++++++ src/main.rs | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 VERSION_INFO.md diff --git a/VERSION_INFO.md b/VERSION_INFO.md new file mode 100644 index 0000000..fbe24c5 --- /dev/null +++ b/VERSION_INFO.md @@ -0,0 +1,7 @@ +# Version information + +| Version | Meaning | +| ------- | -------------- | +| 0.x.1 | beta release 1 | +| x.1.x | dev release 1 | +| 1.x.x | full release 1 | diff --git a/src/main.rs b/src/main.rs index abf8626..f7dce9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::io::Write; mod utils; fn main() { - let version = "0.1.0"; + let version = "0.1.1"; println!("IPass v{}\n", version); let args = utils::get_args(); @@ -26,10 +26,18 @@ fn main() { "import" => import(&args), "export" => export(&args), "rename" => rename(&args), + "version" => version_help(version), _ => help_message(&args), } } +fn version_help(version: &str) { + let mut data = version.split("."); + print!("Major {} ", data.next().unwrap()); + print!("Sub {} ", data.next().unwrap()); + print!("Bugfix {}", data.next().unwrap()); +} + fn help_message(args: &Vec) { let mut help_messages:HashMap = HashMap::new(); @@ -61,6 +69,19 @@ fn help_message(args: &Vec) { "rename".to_string(), "renames an existing entry".to_string(), ); + help_messages.insert( + "import".to_string(), + "import a .ipassx file to your current entries from an optional {directory}".to_string(), + ); + help_messages.insert( + "export".to_string(), + "exports your current entries as an .ipassx file to an optional {directory}".to_string(), + ); + help_messages.insert( + "version".to_string(), + "explains the current version".to_string() + ); + if args.len() < 3 { println!("You can use the following commands:"); @@ -82,6 +103,7 @@ fn list() { } fn add(args: &Vec) { + if args.len() < 3 || args.len() > 4 { println!("Incorrect usage of \"add\""); return; @@ -92,13 +114,15 @@ fn add(args: &Vec) { if args.len() > 3 { pw = args[3].to_owned(); } else { - let char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!\"§$%&/()=?´`²³{[]}\\,.-;:_><|+*#'".as_bytes(); + let alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!\"§$%&/()=?´`²³{[]}\\,.-;:_><|+*#'"; + let char_set:Vec = alphabet.clone().chars().collect(); let mut chars_index: Vec = vec![0;20]; OsRng.fill_bytes(&mut chars_index); let mut chars = String::new(); for index in chars_index { - chars += std::str::from_utf8(&[char_set[(index%(char_set.len() as u8)) as usize]]).unwrap(); + // println!("index: {index} : {}",(index%((alphabet.len()-1) as u8))); + chars += &char_set[(index%((alphabet.len()-1) as u8)) as usize].to_string(); } pw = chars; @@ -115,6 +139,10 @@ fn add(args: &Vec) { } fn get(args: &Vec) { + if args.len() < 3 { + println!("Invalid usage of \"get\""); + return; + } let name = &args[2]; let filepath = &(utils::get_ipass_folder()+name+".ipass"); if std::path::Path::new(filepath).exists() { @@ -164,13 +192,17 @@ fn rename(args: &Vec) { // prog ren old new } fn remove(args: &Vec) { + if args.len() < 3 { + println!("Invalid usage of \"remove\""); + return; + } let name = &args[2]; let filepath = &(utils::get_ipass_folder()+name+".ipass"); if std::path::Path::new(filepath).exists() { if utils::prompt_answer(format!("Are you sure you want to delete {}? [y/N]", name)) == "y" { std::fs::remove_file(filepath).unwrap(); println!("Removed entry \"{}\"", name); - } else{ + } else { println!("Operation cancelled!") } } else {