From def6b003f2694f6ef7deb4b8754ca05dc9c179ae Mon Sep 17 00:00:00 2001 From: prsabahrami Date: Wed, 11 Sep 2024 13:40:41 -0400 Subject: [PATCH] run fmt --- crates/deno_task_shell/src/parser.rs | 63 ++++++++++++--------- crates/deno_task_shell/src/shell/command.rs | 23 ++++---- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/crates/deno_task_shell/src/parser.rs b/crates/deno_task_shell/src/parser.rs index 207dba1..6f8afab 100644 --- a/crates/deno_task_shell/src/parser.rs +++ b/crates/deno_task_shell/src/parser.rs @@ -371,8 +371,9 @@ pub fn debug_parse(input: &str) { } pub fn parse(input: &str) -> Result { - let mut pairs = ShellParser::parse(Rule::FILE, input) - .map_err(|e| miette::Error::new(e.into_miette()).context("Failed to parse input"))?; + let mut pairs = ShellParser::parse(Rule::FILE, input).map_err(|e| { + miette::Error::new(e.into_miette()).context("Failed to parse input") + })?; parse_file(pairs.next().unwrap()) } @@ -393,7 +394,10 @@ fn parse_complete_command(pair: Pair) -> Result { break; } _ => { - return Err(miette!("Unexpected rule in complete_command: {:?}", command.as_rule())); + return Err(miette!( + "Unexpected rule in complete_command: {:?}", + command.as_rule() + )); } } } @@ -444,7 +448,10 @@ fn parse_compound_list( } } _ => { - return Err(miette!("Unexpected rule in compound_list: {:?}", item.as_rule())); + return Err(miette!( + "Unexpected rule in compound_list: {:?}", + item.as_rule() + )); } } } @@ -490,7 +497,9 @@ fn parse_and_or(pair: Pair) -> Result { match items.next() { Some(next_item) => { if next_item.as_rule() == Rule::ASSIGNMENT_WORD { - return Err(miette!("Multiple assignment words before && or || is not supported yet")); + return Err(miette!( + "Multiple assignment words before && or || is not supported yet" + )); } else { let op = match next_item.as_str() { "&&" => BooleanListOperator::And, @@ -545,9 +554,9 @@ fn parse_pipeline(pair: Pair) -> Result { )); } // Get the actual pipe sequence after whitespace - let pipe_sequence = inner.next().ok_or_else(|| { - miette!("Expected pipe sequence after negation") - })?; + let pipe_sequence = inner + .next() + .ok_or_else(|| miette!("Expected pipe sequence after negation"))?; (true, pipe_sequence) } else { // If it's not Bang, this element itself is the pipe_sequence @@ -566,9 +575,9 @@ fn parse_pipe_sequence(pair: Pair) -> Result { let mut inner = pair.into_inner(); // Parse the first command - let first_command = inner.next().ok_or_else(|| { - miette!("Expected at least one command in pipe sequence") - })?; + let first_command = inner + .next() + .ok_or_else(|| miette!("Expected at least one command in pipe sequence"))?; let current = parse_command(first_command)?; // Check if there's a pipe operator @@ -586,9 +595,9 @@ fn parse_pipe_sequence(pair: Pair) -> Result { }; // Parse the rest of the pipe sequence - let next_sequence = inner.next().ok_or_else(|| { - miette!("Expected command after pipe operator") - })?; + let next_sequence = inner + .next() + .ok_or_else(|| miette!("Expected command after pipe operator"))?; let next = parse_pipe_sequence(next_sequence)?; Ok(PipelineInner::PipeSequence(Box::new(PipeSequence { @@ -609,10 +618,7 @@ fn parse_command(pair: Pair) -> Result { Rule::function_definition => { Err(miette!("Function definitions are not supported yet")) } - _ => Err(miette!( - "Unexpected rule in command: {:?}", - inner.as_rule() - )), + _ => Err(miette!("Unexpected rule in command: {:?}", inner.as_rule())), } } @@ -677,13 +683,21 @@ fn parse_simple_command(pair: Pair) -> Result { fn parse_compound_command(pair: Pair) -> Result { let inner = pair.into_inner().next().unwrap(); match inner.as_rule() { - Rule::brace_group => Err(miette!("Unsupported compound command brace_group")), + Rule::brace_group => { + Err(miette!("Unsupported compound command brace_group")) + } Rule::subshell => parse_subshell(inner), Rule::for_clause => Err(miette!("Unsupported compound command for_clause")), - Rule::case_clause => Err(miette!("Unsupported compound command case_clause")), + Rule::case_clause => { + Err(miette!("Unsupported compound command case_clause")) + } Rule::if_clause => Err(miette!("Unsupported compound command if_clause")), - Rule::while_clause => Err(miette!("Unsupported compound command while_clause")), - Rule::until_clause => Err(miette!("Unsupported compound command until_clause")), + Rule::while_clause => { + Err(miette!("Unsupported compound command while_clause")) + } + Rule::until_clause => { + Err(miette!("Unsupported compound command until_clause")) + } _ => Err(miette!( "Unexpected rule in compound_command: {:?}", inner.as_rule() @@ -815,10 +829,7 @@ fn parse_word(pair: Pair) -> Result { } } _ => { - return Err(miette!( - "Unexpected rule in word: {:?}", - pair.as_rule() - )); + return Err(miette!("Unexpected rule in word: {:?}", pair.as_rule())); } } diff --git a/crates/deno_task_shell/src/shell/command.rs b/crates/deno_task_shell/src/shell/command.rs index 0b3fb27..c5c0577 100644 --- a/crates/deno_task_shell/src/shell/command.rs +++ b/crates/deno_task_shell/src/shell/command.rs @@ -13,8 +13,8 @@ use crate::ExecuteResult; use crate::FutureExecuteResult; use crate::ShellCommand; use crate::ShellCommandContext; -use miette::{miette, Result}; use futures::FutureExt; +use miette::{miette, Result}; use thiserror::Error; #[derive(Debug, Clone)] @@ -125,7 +125,9 @@ async fn resolve_command<'a>( // won't have a script with a shebang in it on Windows if command_name.name.contains('/') { if let Some(shebang) = resolve_shebang(&command_path).map_err(|err| { - ResolveCommandError::FailedShebang(FailedShebangError::MietteError(err.to_string())) + ResolveCommandError::FailedShebang(FailedShebangError::MietteError( + err.to_string(), + )) })? { let (shebang_command_name, mut args) = if shebang.string_split { let mut args = parse_shebang_args(&shebang.command, context) @@ -197,13 +199,13 @@ async fn parse_shebang_args( } super::execute::evaluate_args( - cmd.args, - &context.state, - context.stdin.clone(), - context.stderr.clone(), - ) - .await - .map_err(|e| miette!(e.to_string())) + cmd.args, + &context.state, + context.stdin.clone(), + context.stderr.clone(), + ) + .await + .map_err(|e| miette!(e.to_string())) } /// Errors for executable commands. @@ -231,8 +233,7 @@ pub fn resolve_command_path( state: &ShellState, ) -> Result { resolve_command_path_inner(command_name, base_dir, state, || { - std::env::current_exe() - .map_err(|e| miette!(e.to_string())) + std::env::current_exe().map_err(|e| miette!(e.to_string())) }) }