Improve function signatures in aqua command (#88)

This commit is contained in:
folex 2021-05-21 20:55:23 +03:00 committed by GitHub
parent c62a278897
commit 557419fd51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 13 deletions

2
Cargo.lock generated
View File

@ -1457,7 +1457,7 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]] [[package]]
name = "marine" name = "marine"
version = "0.6.3" version = "0.6.4"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"anyhow", "anyhow",

View File

@ -56,12 +56,12 @@ impl fmt::Display for FunctionSignature {
_ => unimplemented!("more than 1 output type is unsupported"), _ => unimplemented!("more than 1 output type is unsupported"),
}; };
if self.arguments.is_empty() { let args = self
writeln!(f, "{}: -> {}", self.name, output) .arguments
} else { .iter()
let args = self.arguments.iter().map(|(_, ty)| ty).format(","); .map(|(name, ty)| format!("{}: {}", name, ty))
writeln!(f, "{}: {} -> {}", self.name, args, output) .format(", ");
} writeln!(f, "{}({}) -> {}", self.name, args, output)
} }
} }

View File

@ -1,7 +1,7 @@
[package] [package]
name = "marine" name = "marine"
description = "Fluence Marine command line tool" description = "Fluence Marine command line tool"
version = "0.6.3" version = "0.6.4"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
repository = "https://github.com/fluencelabs/marine/tools/cli" repository = "https://github.com/fluencelabs/marine/tools/cli"
license = "Apache-2.0" license = "Apache-2.0"

View File

@ -24,6 +24,7 @@ pub const IN_WASM_PATH: &str = "in-wasm-path";
pub const IT_PATH: &str = "it-path"; pub const IT_PATH: &str = "it-path";
pub const OUT_WASM_PATH: &str = "out-wasm-path"; pub const OUT_WASM_PATH: &str = "out-wasm-path";
pub const SERVICE_NAME: &str = "service-name"; pub const SERVICE_NAME: &str = "service-name";
pub const SERVICE_ID: &str = "service-id";
pub const SDK_VERSION: &str = "sdk-version"; pub const SDK_VERSION: &str = "sdk-version";
@ -40,7 +41,14 @@ pub fn aqua<'a, 'b>() -> App<'a, 'b> {
.required(false) .required(false)
.takes_value(true) .takes_value(true)
.short("s") .short("s")
.long("service")
.help("optional service name"), .help("optional service name"),
Arg::with_name(SERVICE_ID)
.required(false)
.takes_value(true)
.short("i")
.long("id")
.help("optional service id"),
]) ])
} }

View File

@ -89,20 +89,24 @@ fn aqua(args: &clap::ArgMatches<'_>) -> Result<(), anyhow::Error> {
println!("{}", record); println!("{}", record);
} }
match args.value_of(args::SERVICE_NAME) { let service_name = match args.value_of(args::SERVICE_NAME) {
Some(service_name) => println!("service {}:", service_name.to_title_case()), Some(service_name) => service_name.into(),
None => { None => {
let service_name = wasm_path let service_name = wasm_path
.file_stem() .file_stem()
.ok_or(anyhow::Error::msg("provided path isn't a path to a file"))?; .ok_or(anyhow::Error::msg("provided path isn't a path to a file"))?;
let service_name = service_name.to_string_lossy().to_title_case();
println!("service {}:", service_name); service_name.to_string_lossy()
} }
};
let service_name = service_name.to_class_case();
match args.value_of(args::SERVICE_ID) {
Some(id) => println!(r#"service {}("{}"):"#, service_name, id),
None => println!("service {}:", service_name),
} }
for sign in module_interface.function_signatures { for sign in module_interface.function_signatures {
println!(" {}", sign); print!(" {}", sign);
} }
Ok(()) Ok(())