diff options
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/cli/main.rs b/cli/main.rs index 8ebf65e16..4955b79d0 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -166,6 +166,9 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> { DenoSubcommand::Install(install_flags) => spawn_subcommand(async { tools::installer::install_command(flags, install_flags).await }), + DenoSubcommand::JSONReference(json_reference) => spawn_subcommand(async move { + display::write_to_stdout_ignore_sigpipe(&deno_core::serde_json::to_vec_pretty(&json_reference.json).unwrap()) + }), DenoSubcommand::Jupyter(jupyter_flags) => spawn_subcommand(async { tools::jupyter::kernel(flags, jupyter_flags).await }), @@ -192,29 +195,47 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> { tools::run::run_from_stdin(flags.clone()).await } else { let result = tools::run::run_script(WorkerExecutionMode::Run, flags.clone(), run_flags.watch).await; - match result { - Ok(v) => Ok(v), - Err(script_err) => { - if script_err.to_string().starts_with(MODULE_NOT_FOUND) { - let mut new_flags = flags.deref().clone(); - let task_flags = TaskFlags { - cwd: None, - task: Some(run_flags.script.clone()), - }; - new_flags.subcommand = DenoSubcommand::Task(task_flags.clone()); - let result = tools::task::execute_script(Arc::new(new_flags), task_flags.clone(), true).await; - match result { - Ok(v) => Ok(v), - Err(_) => { - // Return script error for backwards compatibility. + match result { + Ok(v) => Ok(v), + Err(script_err) => { + if script_err.to_string().starts_with(MODULE_NOT_FOUND) { + if run_flags.bare { + let mut cmd = args::clap_root(); + cmd.build(); + let command_names = cmd.get_subcommands().map(|command| command.get_name()).collect::<Vec<_>>(); + let suggestions = args::did_you_mean(&run_flags.script, command_names); + if !suggestions.is_empty() { + let mut error = clap::error::Error::<clap::error::DefaultFormatter>::new(clap::error::ErrorKind::InvalidSubcommand).with_cmd(&cmd); + error.insert( + clap::error::ContextKind::SuggestedSubcommand, + clap::error::ContextValue::Strings(suggestions), + ); + + Err(error.into()) + } else { Err(script_err) + } + } else { + let mut new_flags = flags.deref().clone(); + let task_flags = TaskFlags { + cwd: None, + task: Some(run_flags.script.clone()), + }; + new_flags.subcommand = DenoSubcommand::Task(task_flags.clone()); + let result = tools::task::execute_script(Arc::new(new_flags), task_flags.clone(), true).await; + match result { + Ok(v) => Ok(v), + Err(_) => { + // Return script error for backwards compatibility. + Err(script_err) + } + } } + } else { + Err(script_err) } - } else { - Err(script_err) } - }, - } + } } }), DenoSubcommand::Serve(serve_flags) => spawn_subcommand(async move { @@ -270,6 +291,9 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> { DenoSubcommand::Publish(publish_flags) => spawn_subcommand(async { tools::registry::publish(flags, publish_flags).await }), + DenoSubcommand::Help(help_flags) => spawn_subcommand(async move { + display::write_to_stdout_ignore_sigpipe(help_flags.help.ansi().to_string().as_bytes()) + }), }; handle.await? |