Skip to content

Commit f68dd89

Browse files
committed
fix: command open sets default flags when calling "from xxx" converters
1 parent 7c16072 commit f68dd89

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

crates/nu-command/src/filesystem/open.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#[allow(deprecated)]
2-
use nu_engine::{command_prelude::*, current_dir, get_eval_block};
2+
use nu_engine::{command_prelude::*, current_dir, eval_call};
33
use nu_protocol::{
44
ast,
5+
debugger::{WithDebug, WithoutDebug},
56
shell_error::{self, io::IoError},
67
DataSource, NuGlob, PipelineMetadata,
78
};
8-
use std::path::{Path, PathBuf};
9+
use std::{
10+
collections::HashMap,
11+
path::{Path, PathBuf},
12+
};
913

1014
#[cfg(feature = "sqlite")]
1115
use crate::database::SQLiteDatabase;
@@ -63,7 +67,6 @@ impl Command for Open {
6367
#[allow(deprecated)]
6468
let cwd = current_dir(engine_state, stack)?;
6569
let mut paths = call.rest::<Spanned<NuGlob>>(engine_state, stack, 0)?;
66-
let eval_block = get_eval_block(engine_state);
6770

6871
if paths.is_empty() && !call.has_positional_args(stack, 0) {
6972
// try to use path from pipeline input if there were no positional or spread args
@@ -192,13 +195,16 @@ impl Command for Open {
192195

193196
match converter {
194197
Some((converter_id, ext)) => {
195-
let decl = engine_state.get_decl(converter_id);
196-
let command_output = if let Some(block_id) = decl.block_id() {
197-
let block = engine_state.get_block(block_id);
198-
eval_block(engine_state, stack, block, stream)
198+
let open_call = ast::Call {
199+
decl_id: converter_id,
200+
head: call_span,
201+
arguments: vec![],
202+
parser_info: HashMap::new(),
203+
};
204+
let command_output = if engine_state.is_debugging() {
205+
eval_call::<WithDebug>(engine_state, stack, &open_call, stream)
199206
} else {
200-
let call = ast::Call::new(call_span);
201-
decl.run(engine_state, stack, &(&call).into(), stream)
207+
eval_call::<WithoutDebug>(engine_state, stack, &open_call, stream)
202208
};
203209
output.push(command_output.map_err(|inner| {
204210
ShellError::GenericError{

crates/nu-command/tests/commands/open.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,20 @@ fn test_open_block_command() {
300300
assert_eq!(actual.out, "abcd")
301301
}
302302

303+
#[test]
304+
fn test_open_with_converter_flags() {
305+
// https://github.com/nushell/nushell/issues/13722
306+
let actual = nu!(
307+
cwd: "tests/fixtures/formats",
308+
r#"
309+
def "from blockcommandparser" [ --flag ] { if $flag { "yes" } else { "no" } }
310+
open sample.blockcommandparser
311+
"#
312+
);
313+
314+
assert_eq!(actual.out, "no")
315+
}
316+
303317
#[test]
304318
fn open_ignore_ansi() {
305319
Playground::setup("open_test_ansi", |dirs, sandbox| {

0 commit comments

Comments
 (0)