Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/shell/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl ShellCommand for SourceCommand {
Ok(content) => {
let state = context.state.clone();
async move {
execute::execute_inner(&content, state)
execute::execute_inner(&content, Some(script_file.display().to_string()), state)
.await
.unwrap_or_else(|e| {
eprintln!("Could not source script: {:?}", script_file);
Expand Down
17 changes: 14 additions & 3 deletions crates/shell/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ use deno_task_shell::{
};
use miette::{Context, IntoDiagnostic};

pub async fn execute_inner(text: &str, state: ShellState) -> miette::Result<ExecuteResult> {
pub async fn execute_inner(
text: &str,
filename: Option<String>,
state: ShellState,
) -> miette::Result<ExecuteResult> {
let list = deno_task_shell::parser::parse(text);

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

if let Err(e) = list {
if let Some(filename) = &filename {
stderr.write_all(format!("Filename: {:?}\n", filename).as_bytes())?;
}
stderr.write_all(format!("Syntax error: {:?}", e).as_bytes())?;
return Ok(ExecuteResult::Exit(1, vec![]));
}
Expand All @@ -30,8 +37,12 @@ pub async fn execute_inner(text: &str, state: ShellState) -> miette::Result<Exec
Ok(result)
}

pub async fn execute(text: &str, state: &mut ShellState) -> miette::Result<i32> {
let result = execute_inner(text, state.clone()).await?;
pub async fn execute(
text: &str,
filename: Option<String>,
state: &mut ShellState,
) -> miette::Result<i32> {
let result = execute_inner(text, filename, state.clone()).await?;

match result {
ExecuteResult::Continue(exit_code, changes, _) => {
Expand Down
14 changes: 9 additions & 5 deletions crates/shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ async fn interactive(state: Option<ShellState>, norc: bool) -> miette::Result<()
let shellrc_file: PathBuf = [home.as_path(), Path::new(".shellrc")].iter().collect();
if !norc && Path::new(shellrc_file.as_path()).exists() {
let line = "source '".to_owned() + shellrc_file.to_str().unwrap() + "'";
let prev_exit_code = execute(&line, &mut state)
.await
.context("Failed to source ~/.shellrc")?;
let prev_exit_code = execute(
&line,
Some(shellrc_file.as_path().display().to_string()),
&mut state,
)
.await
.context("Failed to source ~/.shellrc")?;
state.set_last_command_exit_code(prev_exit_code);
}

Expand Down Expand Up @@ -126,7 +130,7 @@ async fn interactive(state: Option<ShellState>, norc: bool) -> miette::Result<()
rl.add_history_entry(line.as_str()).into_diagnostic()?;

// Process the input (here we just echo it back)
let prev_exit_code = execute(&line, &mut state)
let prev_exit_code = execute(&line, None, &mut state)
.await
.context("Failed to execute")?;
state.set_last_command_exit_code(prev_exit_code);
Expand Down Expand Up @@ -170,7 +174,7 @@ async fn main() -> miette::Result<()> {
debug_parse(&script_text);
return Ok(());
}
let exit_code = execute(&script_text, &mut state).await?;
let exit_code = execute(&script_text, Some(file.display().to_string()), &mut state).await?;
if options.interact {
interactive(Some(state), options.norc).await?;
}
Expand Down
Loading