From c253a8d0a32bf10722df1251ed52e694f8b888dd Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 17 May 2023 21:37:57 +0200 Subject: [PATCH] Adds a Err test on vec_complete --- src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 64c7e7d..fe0efa4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,10 @@ struct Cli { #[arg(short, long, default_value_t = false)] create: bool, + /// Show where the snippet is located + #[arg(short, long, default_value_t = false)] + locate: bool, + /// The list of arguments to give to the snippet /// if the -c flag is used, it's used to create the default arguments #[arg(help = "List of args to give to the snipplet")] @@ -62,6 +66,9 @@ fn create_snippet(args: Cli) { let mut file = match create_dir_all(&save_path) { Ok(()) => { save_path.push(format!("{}.yaml", args.snipplet)); + if args.locate { + println!("Saving snippet to {:?}", save_path); + } File::create(&save_path).unwrap_or_else(|e| { panic!("Couldn't create snippet file at {:?} {:}", save_path, e) }) @@ -107,7 +114,11 @@ fn print_snippet(args: &Cli) { Err(_) => panic!("Couldn't format the snippet !"), Ok(sn) => sn, }; - println!("{}", f_str); + if args.locate { + println!("{:?}", path); + } else { + println!("{}", f_str); + } } /// A snippet ready to be Serialized/Deserialized @@ -219,5 +230,8 @@ mod test { vec!["A", "BB", "CC", "DD"] ); assert_eq!(complete_vec(&eq, &deff).unwrap(), eq); + if let Ok(x) = complete_vec(&big, &deff) { + panic!("Complete vec should return an error ob bigger vecs") + }; } }