Skip to content

Commit

Permalink
feat: add debug mode (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Sep 7, 2024
1 parent ebf9af7 commit 233b7a2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/deno_task_shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ thiserror = "1.0.63"
pest = "2.7.12"
pest_derive = "2.7.12"
dirs = "5.0.1"
pest_ascii_tree = "0.1.0"

[dev-dependencies]
parking_lot = "0.12.3"
Expand Down
5 changes: 5 additions & 0 deletions crates/deno_task_shell/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ pub enum RedirectOpOutput {
#[grammar = "grammar.pest"]
struct ShellParser;

pub fn debug_parse(input: &str) {
let parsed = ShellParser::parse(Rule::FILE, input);
pest_ascii_tree::print_ascii_tree(parsed);
}

pub fn parse(input: &str) -> Result<SequentialList> {
let mut pairs = ShellParser::parse(Rule::FILE, input)?;

Expand Down
8 changes: 8 additions & 0 deletions crates/shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::rc::Rc;
use anyhow::Context;
use clap::Parser;
use completion::ShellCompleter;
use deno_task_shell::parser::debug_parse;
use deno_task_shell::{
execute_sequential_list, AsyncCommandBehavior, ExecuteResult, ShellCommand, ShellPipeReader,
ShellPipeWriter, ShellState,
Expand Down Expand Up @@ -60,6 +61,9 @@ async fn execute(text: &str, state: &mut ShellState) -> anyhow::Result<i32> {
struct Options {
#[clap(short, long)]
file: Option<PathBuf>,

#[clap(short, long)]
debug: bool,
}

fn init_state() -> ShellState {
Expand Down Expand Up @@ -144,6 +148,10 @@ async fn main() -> anyhow::Result<()> {
if let Some(file) = options.file {
let script_text = std::fs::read_to_string(&file).unwrap();
let mut state = init_state();
if options.debug {
debug_parse(&script_text);
return Ok(());
}
execute(&script_text, &mut state).await?;
} else {
interactive().await?;
Expand Down

0 comments on commit 233b7a2

Please sign in to comment.