diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index f00144babf..c446e574df 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -398,8 +398,13 @@ pub async fn run_vec_of_pipelines( } => { for pipeline in pipelines { if let Ok(pipeline_string) = pipeline.as_string() { - let _ = - run_pipeline_standalone(pipeline_string, false, &mut context).await; + let _ = run_pipeline_standalone( + pipeline_string, + false, + &mut context, + false, + ) + .await; } } } @@ -411,7 +416,7 @@ pub async fn run_vec_of_pipelines( } for pipeline in pipelines { - run_pipeline_standalone(pipeline, redirect_stdin, &mut context).await?; + run_pipeline_standalone(pipeline, redirect_stdin, &mut context, true).await?; } Ok(()) } @@ -420,6 +425,7 @@ pub async fn run_pipeline_standalone( pipeline: String, redirect_stdin: bool, context: &mut Context, + exit_on_error: bool, ) -> Result<(), Box> { let line = process_line(Ok(pipeline), context, redirect_stdin, false).await; @@ -448,7 +454,9 @@ pub async fn run_pipeline_standalone( }); context.maybe_print_errors(Text::from(line)); - std::process::exit(1); + if exit_on_error { + std::process::exit(1); + } } _ => {} @@ -502,8 +510,13 @@ pub async fn cli() -> Result<(), Box> { } => { for pipeline in pipelines { if let Ok(pipeline_string) = pipeline.as_string() { - let _ = - run_pipeline_standalone(pipeline_string, false, &mut context).await; + let _ = run_pipeline_standalone( + pipeline_string, + false, + &mut context, + false, + ) + .await; } } } diff --git a/crates/nu-cli/src/commands/classified/external.rs b/crates/nu-cli/src/commands/classified/external.rs index 6343de4fac..d80fa8d089 100644 --- a/crates/nu-cli/src/commands/classified/external.rs +++ b/crates/nu-cli/src/commands/classified/external.rs @@ -444,6 +444,8 @@ fn spawn( process.arg("/c"); process.arg(&command.name); for arg in args { + // Clean the args before we use them: + let arg = arg.replace("|", "\\|"); process.arg(&arg); } process diff --git a/crates/nu-cli/src/commands/help.rs b/crates/nu-cli/src/commands/help.rs index 6861618bfa..1401aa6fca 100644 --- a/crates/nu-cli/src/commands/help.rs +++ b/crates/nu-cli/src/commands/help.rs @@ -76,6 +76,12 @@ impl PerItemCommand for Help { return Ok( get_help(&command.name(), &command.usage(), command.signature()).into(), ); + } else { + return Err(ShellError::labeled_error( + "Can't find command (use 'help commands' for full list)", + "can't find command", + tag, + )); } let help = futures::stream::iter(help); Ok(help.to_output_stream()) diff --git a/crates/nu-cli/src/shell/completer.rs b/crates/nu-cli/src/shell/completer.rs index 3145614c78..9c391f73d1 100644 --- a/crates/nu-cli/src/shell/completer.rs +++ b/crates/nu-cli/src/shell/completer.rs @@ -69,15 +69,15 @@ impl NuCompleter { for command in commands.iter() { let mut pos = replace_pos; - let mut matched = true; + let mut matched = false; if pos < line_chars.len() { for chr in command.chars() { if line_chars[pos] != chr { - matched = false; break; } pos += 1; if pos == line_chars.len() { + matched = true; break; } }