Add -nr flag to repl (#72)

This commit is contained in:
vms 2021-04-09 10:43:22 +03:00 committed by GitHub
parent 80337a04d7
commit 6d4ef8200b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,11 +128,20 @@ impl REPL {
println!("{}", result_msg); println!("{}", result_msg);
} }
fn call_module<'args>(&mut self, mut args: impl Iterator<Item = &'args str>) { fn call_module<'args>(&mut self, args: impl Iterator<Item = &'args str>) {
use itertools::Itertools; use itertools::Itertools;
let mut args = args.peekable();
next_argument!(module_name, args, "Module name should be specified"); next_argument!(module_name, args, "Module name should be specified");
next_argument!(func_name, args, "Function name should be specified"); next_argument!(func_name, args, "Function name should be specified");
let show_result_arg = match args.peek() {
Some(option) if *option == "-nr" => {
args.next();
false
}
Some(_) => true,
None => true,
};
let module_arg: String = args.join(" "); let module_arg: String = args.join(" ");
let module_arg: serde_json::Value = match serde_json::from_str(&module_arg) { let module_arg: serde_json::Value = match serde_json::from_str(&module_arg) {
@ -150,10 +159,14 @@ impl REPL {
.app_service .app_service
.call_module(module_name, func_name, module_arg, <_>::default()) .call_module(module_name, func_name, module_arg, <_>::default())
{ {
Ok(result) => { Ok(result) if show_result_arg => {
let elapsed_time = start.elapsed(); let elapsed_time = start.elapsed();
format!("result: {:?}\n elapsed time: {:?}", result, elapsed_time) format!("result: {:?}\n elapsed time: {:?}", result, elapsed_time)
} }
Ok(_) => {
let elapsed_time = start.elapsed();
format!("call succeeded, elapsed time: {:?}", elapsed_time)
}
Err(e) => format!("call failed with: {}", e), Err(e) => format!("call failed with: {}", e),
}; };