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]]
name = "marine"
version = "0.6.3"
version = "0.6.4"
dependencies = [
"Inflector",
"anyhow",

View File

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

View File

@ -1,7 +1,7 @@
[package]
name = "marine"
description = "Fluence Marine command line tool"
version = "0.6.3"
version = "0.6.4"
authors = ["Fluence Labs"]
repository = "https://github.com/fluencelabs/marine/tools/cli"
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 OUT_WASM_PATH: &str = "out-wasm-path";
pub const SERVICE_NAME: &str = "service-name";
pub const SERVICE_ID: &str = "service-id";
pub const SDK_VERSION: &str = "sdk-version";
@ -40,7 +41,14 @@ pub fn aqua<'a, 'b>() -> App<'a, 'b> {
.required(false)
.takes_value(true)
.short("s")
.long("service")
.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);
}
match args.value_of(args::SERVICE_NAME) {
Some(service_name) => println!("service {}:", service_name.to_title_case()),
let service_name = match args.value_of(args::SERVICE_NAME) {
Some(service_name) => service_name.into(),
None => {
let service_name = wasm_path
.file_stem()
.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 {
println!(" {}", sign);
print!(" {}", sign);
}
Ok(())