diff --git a/tools/cli/src/args.rs b/tools/cli/src/args.rs index ef2780f3..df04b7dd 100644 --- a/tools/cli/src/args.rs +++ b/tools/cli/src/args.rs @@ -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)) +} diff --git a/tools/cli/src/main.rs b/tools/cli/src/main.rs index f4fe56d5..301140d8 100644 --- a/tools/cli/src/main.rs +++ b/tools/cli/src/main.rs @@ -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()), } }