Skip to content

Commit

Permalink
implement source
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Sep 10, 2024
1 parent 16ca6ab commit 4e56b0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 4 additions & 8 deletions crates/shell/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,10 @@ impl ShellCommand for SourceCommand {
if script_file.exists() {
// TODO turn into execute result
let content = fs::read_to_string(script_file).unwrap();
let mut state = context.state.clone();

async move {
execute::execute(&content, &mut state).await.unwrap();
ExecuteResult::from_exit_code(0)
}.boxed_local()
let state = context.state.clone();
async move { execute::execute_inner(&content, state).await.unwrap() }.boxed_local()
} else {
Box::pin(futures::future::ready(ExecuteResult::from_exit_code(1)))
}

Box::pin(futures::future::ready(ExecuteResult::from_exit_code(0)))
}
}
15 changes: 10 additions & 5 deletions crates/shell/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@ use deno_task_shell::{
ShellState,
};

pub async fn execute(text: &str, state: &mut ShellState) -> anyhow::Result<i32> {
pub async fn execute_inner(text: &str, state: ShellState) -> anyhow::Result<ExecuteResult> {
let list = deno_task_shell::parser::parse(text);

let mut stderr = ShellPipeWriter::stderr();
let stderr = ShellPipeWriter::stderr();
let stdout = ShellPipeWriter::stdout();
let stdin = ShellPipeReader::stdin();

if let Err(e) = list {
let _ = stderr.write_line(&format!("Syntax error: {}", e));
return Ok(1);
anyhow::bail!("Syntax error: {}", e);
}

// spawn a sequential list and pipe its output to the environment
let result = execute_sequential_list(
list.unwrap(),
state.clone(),
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
Expand Down

0 comments on commit 4e56b0f

Please sign in to comment.