Add fce repl command (#15)

This commit is contained in:
vms 2020-08-09 12:08:39 +03:00 committed by GitHub
parent e0cbc92f2e
commit 31a15baf76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -63,3 +63,11 @@ pub fn show_wit<'a, 'b>() -> App<'a, 'b> {
.short("i")
.help("path to the Wasm file")])
}
pub fn repl<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("repl")
.about("Start Fluence application service REPL")
.setting(clap::AppSettings::TrailingVarArg)
.setting(clap::AppSettings::AllowLeadingHyphen)
.arg(Arg::from_usage("[optional]... 'fluence repl arguments'").multiple(true))
}

View File

@ -38,7 +38,8 @@ pub fn main() -> std::result::Result<(), anyhow::Error> {
.setting(clap::AppSettings::ArgRequiredElseHelp)
.subcommand(args::build())
.subcommand(args::embed_wit())
.subcommand(args::show_wit());
.subcommand(args::show_wit())
.subcommand(args::repl());
let arg_matches = app.get_matches();
match arg_matches.subcommand() {
@ -76,6 +77,25 @@ pub fn main() -> std::result::Result<(), anyhow::Error> {
Ok(())
}
("repl", Some(args)) => {
use std::process::Command;
// use UNIX-specific API for replacing process image
use std::os::unix::process::CommandExt;
let trailing_args: Vec<&str> = args.values_of("optional").unwrap_or_default().collect();
let mut repl = Command::new("fce-repl");
repl.args(trailing_args);
let error = repl.exec();
if error.kind() == std::io::ErrorKind::NotFound {
println!("fce-repl not found, run `cargo +nightly install frepl` to install it");
} else {
// this branch should be executed if exec was successful, so just else if fine here
println!("error occurred: {:?}", error);
}
Ok(())
}
c => Err(crate::errors::CLIError::NoSuchCommand(c.0.to_string()).into()),
}
}