mirror of
https://github.com/nushell/nushell.git
synced 2025-04-26 06:08:21 +02:00
fix: command open
sets default flags when calling "from xxx" converters (#15383)
Fixes #13722 # Description Simple solution: `eval_block` -> `eval_call` with empty arguments # User-Facing Changes Should be none. # Tests + Formatting +1 # After Submitting
This commit is contained in:
parent
bf1f2d5ebd
commit
e10ac2ede6
@ -1,11 +1,15 @@
|
|||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
use nu_engine::{command_prelude::*, current_dir, get_eval_block};
|
use nu_engine::{command_prelude::*, current_dir, eval_call};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast,
|
ast,
|
||||||
|
debugger::{WithDebug, WithoutDebug},
|
||||||
shell_error::{self, io::IoError},
|
shell_error::{self, io::IoError},
|
||||||
DataSource, NuGlob, PipelineMetadata,
|
DataSource, NuGlob, PipelineMetadata,
|
||||||
};
|
};
|
||||||
use std::path::{Path, PathBuf};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
#[cfg(feature = "sqlite")]
|
||||||
use crate::database::SQLiteDatabase;
|
use crate::database::SQLiteDatabase;
|
||||||
@ -63,7 +67,6 @@ impl Command for Open {
|
|||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
let cwd = current_dir(engine_state, stack)?;
|
let cwd = current_dir(engine_state, stack)?;
|
||||||
let mut paths = call.rest::<Spanned<NuGlob>>(engine_state, stack, 0)?;
|
let mut paths = call.rest::<Spanned<NuGlob>>(engine_state, stack, 0)?;
|
||||||
let eval_block = get_eval_block(engine_state);
|
|
||||||
|
|
||||||
if paths.is_empty() && !call.has_positional_args(stack, 0) {
|
if paths.is_empty() && !call.has_positional_args(stack, 0) {
|
||||||
// try to use path from pipeline input if there were no positional or spread args
|
// try to use path from pipeline input if there were no positional or spread args
|
||||||
@ -192,13 +195,16 @@ impl Command for Open {
|
|||||||
|
|
||||||
match converter {
|
match converter {
|
||||||
Some((converter_id, ext)) => {
|
Some((converter_id, ext)) => {
|
||||||
let decl = engine_state.get_decl(converter_id);
|
let open_call = ast::Call {
|
||||||
let command_output = if let Some(block_id) = decl.block_id() {
|
decl_id: converter_id,
|
||||||
let block = engine_state.get_block(block_id);
|
head: call_span,
|
||||||
eval_block(engine_state, stack, block, stream)
|
arguments: vec![],
|
||||||
|
parser_info: HashMap::new(),
|
||||||
|
};
|
||||||
|
let command_output = if engine_state.is_debugging() {
|
||||||
|
eval_call::<WithDebug>(engine_state, stack, &open_call, stream)
|
||||||
} else {
|
} else {
|
||||||
let call = ast::Call::new(call_span);
|
eval_call::<WithoutDebug>(engine_state, stack, &open_call, stream)
|
||||||
decl.run(engine_state, stack, &(&call).into(), stream)
|
|
||||||
};
|
};
|
||||||
output.push(command_output.map_err(|inner| {
|
output.push(command_output.map_err(|inner| {
|
||||||
ShellError::GenericError{
|
ShellError::GenericError{
|
||||||
|
@ -300,6 +300,20 @@ fn test_open_block_command() {
|
|||||||
assert_eq!(actual.out, "abcd")
|
assert_eq!(actual.out, "abcd")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_open_with_converter_flags() {
|
||||||
|
// https://github.com/nushell/nushell/issues/13722
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats",
|
||||||
|
r#"
|
||||||
|
def "from blockcommandparser" [ --flag ] { if $flag { "yes" } else { "no" } }
|
||||||
|
open sample.blockcommandparser
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "no")
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn open_ignore_ansi() {
|
fn open_ignore_ansi() {
|
||||||
Playground::setup("open_test_ansi", |dirs, sandbox| {
|
Playground::setup("open_test_ansi", |dirs, sandbox| {
|
||||||
|
Loading…
Reference in New Issue
Block a user