mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
Allow open to work with 'from ...' block commands (#5049)
* Remove panic from BlockCommands run function Instead of panicing, the run method now returns an error to prevent nushell from unexpected termination. * Add ability to open command to run with blocks The open command tries to parse the content of the file if there is a command called 'from (file ending)'. This works fine if the command was 'built in' because the run method doesn't fail in this case. It did fail on a BlockCommand, though. This change will first probe if the command contains a block and evaluate it, if this is the case. If there is no block, it will run the command the same way as before. * Add test open files with BlockCommands * Update open.rs * Adjust file type on open with BlockCommand parser Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
This commit is contained in:
@ -260,3 +260,20 @@ fn open_dir_is_ls() {
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_open_block_command() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"
|
||||
def "from blockcommandparser" [] { lines | split column ",|," }
|
||||
let values = (open sample.blockcommandparser)
|
||||
echo ($values | get column1 | get 0)
|
||||
echo ($values | get column2 | get 0)
|
||||
echo ($values | get column1 | get 1)
|
||||
echo ($values | get column2 | get 1)
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "abcd")
|
||||
}
|
||||
|
Reference in New Issue
Block a user