Skip to content

Commit

Permalink
Added support for set -e
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Nov 27, 2024
1 parent cc84630 commit 7673439
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 54 deletions.
76 changes: 48 additions & 28 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/deno_task_shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ shell = ["futures", "glob", "os_pipe", "path-dedot", "tokio", "tokio-util"]
serialization = ["serde"]

[dependencies]
futures = { version = "0.3.30", optional = true }
futures = { version = "0.3.31", optional = true }
glob = { version = "0.3.1", optional = true }
path-dedot = { version = "3.1.1", optional = true }
tokio = { version = "1", features = ["fs", "io-std", "io-util", "macros", "process", "rt-multi-thread", "sync", "time"], optional = true }
tokio-util = { version = "0.7.12", optional = true }
os_pipe = { version = "1.2.1", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
thiserror = "1.0.63"
thiserror = "2.0.3"
pest = { version="2.7.13", features = ["miette-error"] }
pest_derive = "2.7.12"
dirs = "5.0.1"
Expand Down
4 changes: 2 additions & 2 deletions crates/deno_task_shell/src/shell/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ async fn resolve_command<'a>(
}
}

return Ok(ResolvedCommand {
Ok(ResolvedCommand {
command_name: CommandName::Resolved(command_path),
args: Cow::Borrowed(original_args),
});
})
}

async fn parse_shebang_args(
Expand Down
24 changes: 18 additions & 6 deletions crates/deno_task_shell/src/shell/commands/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use miette::Result;

#[derive(Debug, PartialEq, Eq)]
pub enum ArgKind<'a> {
ShortFlag(char),
PlusShortFlag(char),
MinusShortFlag(char),
LongFlag(&'a str),
Arg(&'a str),
}
Expand All @@ -19,9 +20,12 @@ impl<'a> ArgKind<'a> {
ArgKind::LongFlag(name) => {
bail!("unsupported flag: --{}", name)
}
ArgKind::ShortFlag(name) => {
ArgKind::MinusShortFlag(name) => {
bail!("unsupported flag: -{}", name)
}
ArgKind::PlusShortFlag(name) => {
bail!("unsupported flag: +{}", name)
}
}
}
}
Expand All @@ -43,7 +47,15 @@ pub fn parse_arg_kinds(flags: &[String]) -> Vec<ArgKind> {
result.push(ArgKind::Arg(arg));
} else {
for c in flags.chars() {
result.push(ArgKind::ShortFlag(c));
result.push(ArgKind::MinusShortFlag(c));
}
}
} else if let Some(flags) = arg.strip_prefix('+') {
if flags.parse::<f64>().is_ok() {
result.push(ArgKind::Arg(arg));
} else {
for c in flags.chars() {
result.push(ArgKind::PlusShortFlag(c));
}
}
} else {
Expand Down Expand Up @@ -76,9 +88,9 @@ mod test {
assert_eq!(
args,
vec![
ArgKind::ShortFlag('f'),
ArgKind::ShortFlag('a'),
ArgKind::ShortFlag('b'),
ArgKind::MinusShortFlag('f'),
ArgKind::MinusShortFlag('a'),
ArgKind::MinusShortFlag('b'),
ArgKind::LongFlag("force"),
ArgKind::Arg("testing"),
ArgKind::Arg("other"),
Expand Down
4 changes: 2 additions & 2 deletions crates/deno_task_shell/src/shell/commands/cp_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ fn parse_cp_args(cwd: &Path, args: Vec<String>) -> Result<CpFlags> {
paths.push(arg);
}
ArgKind::LongFlag("recursive")
| ArgKind::ShortFlag('r')
| ArgKind::ShortFlag('R') => {
| ArgKind::MinusShortFlag('r')
| ArgKind::MinusShortFlag('R') => {
recursive = true;
}
_ => arg.bail_unsupported()?,
Expand Down
2 changes: 1 addition & 1 deletion crates/deno_task_shell/src/shell/commands/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn parse_args(args: Vec<String>) -> Result<HeadFlags> {
// TODO: support multiple files
bail!("only one file is supported for now");
}
ArgKind::ShortFlag('n') => match iterator.next() {
ArgKind::MinusShortFlag('n') => match iterator.next() {
Some(ArgKind::Arg(arg)) => {
lines = Some(arg.parse::<u64>().into_diagnostic()?);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/deno_task_shell/src/shell/commands/mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ fn parse_args(args: Vec<String>) -> Result<MkdirFlags> {

for arg in parse_arg_kinds(&args) {
match arg {
ArgKind::LongFlag("parents") | ArgKind::ShortFlag('p') => {
ArgKind::LongFlag("parents") | ArgKind::MinusShortFlag('p') => {
result.parents = true;
}
ArgKind::Arg(path) => {
result.paths.push(path.to_string());
}
ArgKind::LongFlag(_) | ArgKind::ShortFlag(_) => arg.bail_unsupported()?,
ArgKind::LongFlag(_) | ArgKind::MinusShortFlag(_) | ArgKind::PlusShortFlag(_)=> arg.bail_unsupported()?,
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/deno_task_shell/src/shell/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use futures::future::LocalBoxFuture;

pub use executable::ExecutableCommand;

pub use args::parse_arg_kinds;
pub use args::ArgKind;

use super::types::ExecuteResult;
use super::types::FutureExecuteResult;
use super::types::ShellPipeReader;
Expand Down
4 changes: 2 additions & 2 deletions crates/deno_task_shell/src/shell/commands/pwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ fn parse_args(args: Vec<String>) -> Result<PwdFlags> {
let mut logical = false;
for arg in parse_arg_kinds(&args) {
match arg {
ArgKind::ShortFlag('L') => {
ArgKind::MinusShortFlag('L') => {
logical = true;
}
ArgKind::ShortFlag('P') => {
ArgKind::MinusShortFlag('P') => {
// ignore, this is the default
}
ArgKind::Arg(_) => {
Expand Down
10 changes: 5 additions & 5 deletions crates/deno_task_shell/src/shell/commands/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ fn parse_args(args: Vec<String>) -> Result<RmFlags> {
for arg in parse_arg_kinds(&args) {
match arg {
ArgKind::LongFlag("recursive")
| ArgKind::ShortFlag('r')
| ArgKind::ShortFlag('R') => {
| ArgKind::MinusShortFlag('r')
| ArgKind::MinusShortFlag('R') => {
result.recursive = true;
}
ArgKind::LongFlag("dir") | ArgKind::ShortFlag('d') => {
ArgKind::LongFlag("dir") | ArgKind::MinusShortFlag('d') => {
result.dir = true;
}
ArgKind::LongFlag("force") | ArgKind::ShortFlag('f') => {
ArgKind::LongFlag("force") | ArgKind::MinusShortFlag('f') => {
result.force = true;
}
ArgKind::Arg(path) => {
result.paths.push(path.to_string());
}
ArgKind::LongFlag(_) | ArgKind::ShortFlag(_) => arg.bail_unsupported()?,
ArgKind::LongFlag(_) | ArgKind::MinusShortFlag(_) | ArgKind::PlusShortFlag(_) => arg.bail_unsupported()?,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/deno_task_shell/src/shell/commands/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn parse_args(args: Vec<String>) -> Result<u64> {
bail!("error parsing argument '{}' to number: {}", arg, err);
}
},
ArgKind::LongFlag(_) | ArgKind::ShortFlag(_) => arg.bail_unsupported()?,
ArgKind::LongFlag(_) | ArgKind::MinusShortFlag(_) | ArgKind::PlusShortFlag(_) => arg.bail_unsupported()?,
}
}
if !had_value {
Expand Down
5 changes: 3 additions & 2 deletions crates/deno_task_shell/src/shell/commands/xargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,17 @@ fn parse_args(args: Vec<String>) -> Result<XargsFlags> {
ArgKind::Arg(arg) => {
initial_args.push(arg.to_string());
}
ArgKind::ShortFlag(f) => initial_args.push(format!("-{f}")),
ArgKind::MinusShortFlag(f) => initial_args.push(format!("-{f}")),
ArgKind::LongFlag(f) => initial_args.push(format!("--{f}")),
_ => continue
}
}
}
}
ArgKind::LongFlag("null") => {
is_null_delimited = true;
}
ArgKind::ShortFlag('d') => match iterator.next() {
ArgKind::MinusShortFlag('d') => match iterator.next() {
Some(ArgKind::Arg(arg)) => {
delimiter = Some(parse_delimiter(arg)?);
}
Expand Down
Loading

0 comments on commit 7673439

Please sign in to comment.