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 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,
));
}
}
};

View File

@ -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"));
}