mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
enable logger by default in repl
This commit is contained in:
parent
52be0dd5ed
commit
2a3fa98fef
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -720,7 +720,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fcli"
|
name = "fcli"
|
||||||
version = "0.1.30"
|
version = "0.1.31"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
@ -898,7 +898,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "frepl"
|
name = "frepl"
|
||||||
version = "0.1.30"
|
version = "0.1.32"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "frepl"
|
name = "frepl"
|
||||||
description = "Fluence FCE REPL intended for testing purposes"
|
description = "Fluence FCE REPL intended for testing purposes"
|
||||||
version = "0.1.31"
|
version = "0.1.32"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
repository = "https://github.com/fluencelabs/fce/tools/repl"
|
repository = "https://github.com/fluencelabs/fce/tools/repl"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
@ -19,6 +19,7 @@ mod print_state;
|
|||||||
use crate::ReplResult;
|
use crate::ReplResult;
|
||||||
|
|
||||||
use fluence_app_service::AppService;
|
use fluence_app_service::AppService;
|
||||||
|
use fluence_app_service::FaaSModuleConfig;
|
||||||
use fluence_app_service::TomlAppServiceConfig;
|
use fluence_app_service::TomlAppServiceConfig;
|
||||||
use print_state::print_envs;
|
use print_state::print_envs;
|
||||||
use print_state::print_fs_state;
|
use print_state::print_fs_state;
|
||||||
@ -34,7 +35,7 @@ macro_rules! next_argument {
|
|||||||
$arg_name
|
$arg_name
|
||||||
} else {
|
} else {
|
||||||
println!($error_msg);
|
println!($error_msg);
|
||||||
return true;
|
return;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -50,31 +51,53 @@ impl REPL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true, it should be the last executed command.
|
/// Returns true, it should be the last executed command.
|
||||||
pub fn execute<'a>(&mut self, mut args: impl Iterator<Item = &'a str>) -> bool {
|
pub fn execute<'args>(&mut self, mut args: impl Iterator<Item = &'args str>) -> bool {
|
||||||
match args.next() {
|
match args.next() {
|
||||||
Some("new") => {
|
Some("new") => self.new_service(args),
|
||||||
|
Some("load") => self.load_module(args),
|
||||||
|
Some("unload") => self.unload_module(args),
|
||||||
|
Some("call") => self.call_module(args),
|
||||||
|
Some("envs") => self.show_envs(args),
|
||||||
|
Some("fs") => self.show_fs(args),
|
||||||
|
Some("interface") => self.show_interface(),
|
||||||
|
Some("q") | Some("quit") => {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => print_help(),
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_service<'args>(&mut self, mut args: impl Iterator<Item = &'args str>) {
|
||||||
match Self::create_app_service(args.next()) {
|
match Self::create_app_service(args.next()) {
|
||||||
Ok(service) => self.app_service = service,
|
Ok(service) => self.app_service = service,
|
||||||
Err(e) => println!("failed to create a new application service: {}", e),
|
Err(e) => println!("failed to create a new application service: {}", e),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Some("load") => {
|
|
||||||
|
fn load_module<'args>(&mut self, mut args: impl Iterator<Item = &'args str>) {
|
||||||
next_argument!(module_name, args, "Module name should be specified");
|
next_argument!(module_name, args, "Module name should be specified");
|
||||||
next_argument!(module_path, args, "Module path should be specified");
|
next_argument!(module_path, args, "Module path should be specified");
|
||||||
|
|
||||||
let wasm_bytes = fs::read(module_path);
|
let wasm_bytes = fs::read(module_path);
|
||||||
if let Err(e) = wasm_bytes {
|
if let Err(e) = wasm_bytes {
|
||||||
println!("failed to read wasm module: {}", e);
|
println!("failed to read wasm module: {}", e);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
let config = FaaSModuleConfig {
|
||||||
|
logger_enabled: true,
|
||||||
|
..<_>::default()
|
||||||
|
};
|
||||||
let result_msg = match self
|
let result_msg = match self
|
||||||
.app_service
|
.app_service
|
||||||
.load_module::<String, fluence_app_service::FaaSModuleConfig>(
|
.load_module::<String, fluence_app_service::FaaSModuleConfig>(
|
||||||
module_name.into(),
|
module_name.into(),
|
||||||
&wasm_bytes.unwrap(),
|
&wasm_bytes.unwrap(),
|
||||||
None,
|
Some(config),
|
||||||
) {
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let elapsed_time = start.elapsed();
|
let elapsed_time = start.elapsed();
|
||||||
@ -87,7 +110,8 @@ impl REPL {
|
|||||||
};
|
};
|
||||||
println!("{}", result_msg);
|
println!("{}", result_msg);
|
||||||
}
|
}
|
||||||
Some("unload") => {
|
|
||||||
|
fn unload_module<'args>(&mut self, mut args: impl Iterator<Item = &'args str>) {
|
||||||
next_argument!(module_name, args, "Module name should be specified");
|
next_argument!(module_name, args, "Module name should be specified");
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
@ -103,7 +127,8 @@ impl REPL {
|
|||||||
};
|
};
|
||||||
println!("{}", result_msg);
|
println!("{}", result_msg);
|
||||||
}
|
}
|
||||||
Some("call") => {
|
|
||||||
|
fn call_module<'args>(&mut self, mut args: impl Iterator<Item = &'args str>) {
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
next_argument!(module_name, args, "Module name should be specified");
|
next_argument!(module_name, args, "Module name should be specified");
|
||||||
@ -114,7 +139,7 @@ impl REPL {
|
|||||||
Ok(module_arg) => module_arg,
|
Ok(module_arg) => module_arg,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("incorrect arguments {}", e);
|
println!("incorrect arguments {}", e);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -132,34 +157,30 @@ impl REPL {
|
|||||||
}
|
}
|
||||||
Err(e) => format!("execution failed with {:?}", e),
|
Err(e) => format!("execution failed with {:?}", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
}
|
}
|
||||||
Some("envs") => {
|
|
||||||
|
fn show_envs<'args>(&mut self, mut args: impl Iterator<Item = &'args str>) {
|
||||||
next_argument!(module_name, args, "Module name should be specified");
|
next_argument!(module_name, args, "Module name should be specified");
|
||||||
match self.app_service.get_wasi_state(module_name) {
|
match self.app_service.get_wasi_state(module_name) {
|
||||||
Ok(wasi_state) => print_envs(module_name, wasi_state),
|
Ok(wasi_state) => print_envs(module_name, wasi_state),
|
||||||
Err(e) => println!("{}", e),
|
Err(e) => println!("{}", e),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Some("fs") => {
|
|
||||||
|
fn show_fs<'args>(&mut self, mut args: impl Iterator<Item = &'args str>) {
|
||||||
next_argument!(module_name, args, "Module name should be specified");
|
next_argument!(module_name, args, "Module name should be specified");
|
||||||
match self.app_service.get_wasi_state(module_name) {
|
match self.app_service.get_wasi_state(module_name) {
|
||||||
Ok(wasi_state) => print_fs_state(wasi_state),
|
Ok(wasi_state) => print_fs_state(wasi_state),
|
||||||
Err(e) => println!("{}", e),
|
Err(e) => println!("{}", e),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Some("interface") => {
|
|
||||||
|
fn show_interface(&mut self) {
|
||||||
let interface = self.app_service.get_full_interface();
|
let interface = self.app_service.get_full_interface();
|
||||||
print!("Application service interface:\n{}", interface);
|
|
||||||
}
|
|
||||||
Some("q") | Some("quit") => {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => print_help(),
|
print!("Loaded modules interface:\n{}", interface);
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_app_service<S: Into<PathBuf>>(config_file_path: Option<S>) -> ReplResult<AppService> {
|
fn create_app_service<S: Into<PathBuf>>(config_file_path: Option<S>) -> ReplResult<AppService> {
|
||||||
|
Loading…
Reference in New Issue
Block a user