From c4cb3a77cb8b7b7845219fcad4110ed69a029f13 Mon Sep 17 00:00:00 2001 From: raccmonteiro <3062698+raccmonteiro@users.noreply.github.com> Date: Wed, 9 Nov 2022 23:25:32 +0000 Subject: [PATCH] command `open` returns error when does not have parameters (#7048) (#7058) test Co-authored-by: Ricardo Monteiro --- crates/nu-command/src/filesystem/open.rs | 36 +++++++++--------------- crates/nu-command/tests/commands/open.rs | 12 ++++++++ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index 2bfb28916..f30f3d313 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -1,16 +1,18 @@ use crate::filesystem::util::BufferedReader; -use nu_engine::{eval_block, get_full_help, CallExt}; +use nu_engine::{eval_block, CallExt}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Category, Example, IntoPipelineData, PipelineData, RawStream, ShellError, Signature, Spanned, - SyntaxShape, Value, + Category, Example, PipelineData, RawStream, ShellError, Signature, Spanned, SyntaxShape, Value, }; use std::io::BufReader; #[cfg(feature = "database")] use crate::database::SQLiteDatabase; +#[cfg(feature = "database")] +use nu_protocol::IntoPipelineData; + #[cfg(unix)] use std::os::unix::fs::PermissionsExt; use std::path::Path; @@ -67,29 +69,17 @@ impl Command for Open { // Collect a filename from the input match input { PipelineData::Value(Value::Nothing { .. }, ..) => { - return Ok(Value::String { - val: get_full_help( - &Open.signature(), - &Open.examples(), - engine_state, - stack, - ), - span: call.head, - } - .into_pipeline_data()) + return Err(ShellError::MissingParameter( + "needs filename".to_string(), + call.head, + )) } PipelineData::Value(val, ..) => val.as_spanned_string()?, _ => { - return Ok(Value::String { - val: get_full_help( - &Open.signature(), - &Open.examples(), - engine_state, - stack, - ), - span: call.head, - } - .into_pipeline_data()) + return Err(ShellError::MissingParameter( + "needs filename".to_string(), + call.head, + )); } } }; diff --git a/crates/nu-command/tests/commands/open.rs b/crates/nu-command/tests/commands/open.rs index 0cdfe36ea..88857f0a8 100644 --- a/crates/nu-command/tests/commands/open.rs +++ b/crates/nu-command/tests/commands/open.rs @@ -299,3 +299,15 @@ fn open_ignore_ansi() { assert!(actual.err.is_empty()); }) } + +#[test] +fn open_no_parameter() { + let actual = nu!( + cwd: "tests/fixtures/formats", + r#" + open + "# + ); + + assert!(actual.err.contains("needs filename")); +}