command open returns error when does not have parameters (#7048) (#7058)

test

Co-authored-by: Ricardo Monteiro <ricardo.monteiro@getmanta.com>
This commit is contained in:
raccmonteiro 2022-11-09 23:25:32 +00:00 committed by GitHub
parent aed8d3800b
commit c4cb3a77cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 23 deletions

View File

@ -1,16 +1,18 @@
use crate::filesystem::util::BufferedReader; 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::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, RawStream, ShellError, Signature, Spanned, Category, Example, PipelineData, RawStream, ShellError, Signature, Spanned, SyntaxShape, Value,
SyntaxShape, Value,
}; };
use std::io::BufReader; use std::io::BufReader;
#[cfg(feature = "database")] #[cfg(feature = "database")]
use crate::database::SQLiteDatabase; use crate::database::SQLiteDatabase;
#[cfg(feature = "database")]
use nu_protocol::IntoPipelineData;
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use std::path::Path; use std::path::Path;
@ -67,29 +69,17 @@ impl Command for Open {
// Collect a filename from the input // Collect a filename from the input
match input { match input {
PipelineData::Value(Value::Nothing { .. }, ..) => { PipelineData::Value(Value::Nothing { .. }, ..) => {
return Ok(Value::String { return Err(ShellError::MissingParameter(
val: get_full_help( "needs filename".to_string(),
&Open.signature(), call.head,
&Open.examples(), ))
engine_state,
stack,
),
span: call.head,
}
.into_pipeline_data())
} }
PipelineData::Value(val, ..) => val.as_spanned_string()?, PipelineData::Value(val, ..) => val.as_spanned_string()?,
_ => { _ => {
return Ok(Value::String { return Err(ShellError::MissingParameter(
val: get_full_help( "needs filename".to_string(),
&Open.signature(), call.head,
&Open.examples(), ));
engine_state,
stack,
),
span: call.head,
}
.into_pipeline_data())
} }
} }
}; };

View File

@ -299,3 +299,15 @@ fn open_ignore_ansi() {
assert!(actual.err.is_empty()); 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"));
}