-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use anyhow::Context; | ||
use deno_task_shell::{ | ||
execute_sequential_list, AsyncCommandBehavior, ExecuteResult, ShellPipeReader, ShellPipeWriter, | ||
ShellState, | ||
}; | ||
|
||
pub async fn execute_inner(text: &str, state: ShellState) -> anyhow::Result<ExecuteResult> { | ||
let list = deno_task_shell::parser::parse(text); | ||
|
||
let stderr = ShellPipeWriter::stderr(); | ||
let stdout = ShellPipeWriter::stdout(); | ||
let stdin = ShellPipeReader::stdin(); | ||
|
||
if let Err(e) = list { | ||
anyhow::bail!("Syntax error: {}", e); | ||
} | ||
|
||
// spawn a sequential list and pipe its output to the environment | ||
let result = execute_sequential_list( | ||
list.unwrap(), | ||
state, | ||
stdin, | ||
stdout, | ||
stderr, | ||
AsyncCommandBehavior::Wait, | ||
) | ||
.await; | ||
|
||
Ok(result) | ||
} | ||
|
||
pub async fn execute(text: &str, state: &mut ShellState) -> anyhow::Result<i32> { | ||
let result = execute_inner(text, state.clone()).await?; | ||
|
||
match result { | ||
ExecuteResult::Continue(exit_code, changes, _) => { | ||
// set CWD to the last command's CWD | ||
state.apply_changes(&changes); | ||
std::env::set_current_dir(state.cwd()).context("Failed to set CWD")?; | ||
Ok(exit_code) | ||
} | ||
ExecuteResult::Exit(_, _) => Ok(0), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters