Skip to content

Commit

Permalink
run fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Sep 11, 2024
1 parent e77436e commit def6b00
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
63 changes: 37 additions & 26 deletions crates/deno_task_shell/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ pub fn debug_parse(input: &str) {
}

pub fn parse(input: &str) -> Result<SequentialList> {
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())
}
Expand All @@ -393,7 +394,10 @@ fn parse_complete_command(pair: Pair<Rule>) -> Result<SequentialList> {
break;
}
_ => {
return Err(miette!("Unexpected rule in complete_command: {:?}", command.as_rule()));
return Err(miette!(
"Unexpected rule in complete_command: {:?}",
command.as_rule()
));
}
}
}
Expand Down Expand Up @@ -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()
));
}
}
}
Expand Down Expand Up @@ -490,7 +497,9 @@ fn parse_and_or(pair: Pair<Rule>) -> Result<Sequence> {
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,
Expand Down Expand Up @@ -545,9 +554,9 @@ fn parse_pipeline(pair: Pair<Rule>) -> Result<Sequence> {
));
}
// 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
Expand All @@ -566,9 +575,9 @@ fn parse_pipe_sequence(pair: Pair<Rule>) -> Result<PipelineInner> {
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
Expand All @@ -586,9 +595,9 @@ fn parse_pipe_sequence(pair: Pair<Rule>) -> Result<PipelineInner> {
};

// 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 {
Expand All @@ -609,10 +618,7 @@ fn parse_command(pair: Pair<Rule>) -> Result<Command> {
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())),
}
}

Expand Down Expand Up @@ -677,13 +683,21 @@ fn parse_simple_command(pair: Pair<Rule>) -> Result<Command> {
fn parse_compound_command(pair: Pair<Rule>) -> Result<Command> {
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()
Expand Down Expand Up @@ -815,10 +829,7 @@ fn parse_word(pair: Pair<Rule>) -> Result<Word> {
}
}
_ => {
return Err(miette!(
"Unexpected rule in word: {:?}",
pair.as_rule()
));
return Err(miette!("Unexpected rule in word: {:?}", pair.as_rule()));
}
}

Expand Down
23 changes: 12 additions & 11 deletions crates/deno_task_shell/src/shell/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -231,8 +233,7 @@ pub fn resolve_command_path(
state: &ShellState,
) -> Result<PathBuf, ResolveCommandPathError> {
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()))
})
}

Expand Down

0 comments on commit def6b00

Please sign in to comment.