Adds a Err test on vec_complete
This commit is contained in:
parent
6374360f2f
commit
c253a8d0a3
16
src/main.rs
16
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")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue