From f90b8ed920945fc1165e37269e17cb5d33f3d4fc Mon Sep 17 00:00:00 2001 From: prsabahrami Date: Wed, 27 Nov 2024 16:26:48 -0500 Subject: [PATCH] run fmt --- .../src/shell/commands/mkdir.rs | 4 +- .../deno_task_shell/src/shell/commands/rm.rs | 4 +- .../src/shell/commands/sleep.rs | 4 +- .../src/shell/commands/xargs.rs | 2 +- crates/deno_task_shell/src/shell/mod.rs | 2 +- crates/deno_task_shell/src/shell/types.rs | 9 ++-- crates/shell/src/commands/mod.rs | 8 +-- crates/shell/src/commands/set.rs | 54 +++++++++---------- 8 files changed, 48 insertions(+), 39 deletions(-) diff --git a/crates/deno_task_shell/src/shell/commands/mkdir.rs b/crates/deno_task_shell/src/shell/commands/mkdir.rs index badde86..5dbc7fb 100644 --- a/crates/deno_task_shell/src/shell/commands/mkdir.rs +++ b/crates/deno_task_shell/src/shell/commands/mkdir.rs @@ -81,7 +81,9 @@ fn parse_args(args: Vec) -> Result { ArgKind::Arg(path) => { result.paths.push(path.to_string()); } - ArgKind::LongFlag(_) | ArgKind::MinusShortFlag(_) | ArgKind::PlusShortFlag(_)=> arg.bail_unsupported()?, + ArgKind::LongFlag(_) + | ArgKind::MinusShortFlag(_) + | ArgKind::PlusShortFlag(_) => arg.bail_unsupported()?, } } diff --git a/crates/deno_task_shell/src/shell/commands/rm.rs b/crates/deno_task_shell/src/shell/commands/rm.rs index e69c355..97114a4 100644 --- a/crates/deno_task_shell/src/shell/commands/rm.rs +++ b/crates/deno_task_shell/src/shell/commands/rm.rs @@ -108,7 +108,9 @@ fn parse_args(args: Vec) -> Result { ArgKind::Arg(path) => { result.paths.push(path.to_string()); } - ArgKind::LongFlag(_) | ArgKind::MinusShortFlag(_) | ArgKind::PlusShortFlag(_) => arg.bail_unsupported()?, + ArgKind::LongFlag(_) + | ArgKind::MinusShortFlag(_) + | ArgKind::PlusShortFlag(_) => arg.bail_unsupported()?, } } diff --git a/crates/deno_task_shell/src/shell/commands/sleep.rs b/crates/deno_task_shell/src/shell/commands/sleep.rs index 0a5b3f2..eab9662 100644 --- a/crates/deno_task_shell/src/shell/commands/sleep.rs +++ b/crates/deno_task_shell/src/shell/commands/sleep.rs @@ -86,7 +86,9 @@ fn parse_args(args: Vec) -> Result { bail!("error parsing argument '{}' to number: {}", arg, err); } }, - ArgKind::LongFlag(_) | ArgKind::MinusShortFlag(_) | ArgKind::PlusShortFlag(_) => arg.bail_unsupported()?, + ArgKind::LongFlag(_) + | ArgKind::MinusShortFlag(_) + | ArgKind::PlusShortFlag(_) => arg.bail_unsupported()?, } } if !had_value { diff --git a/crates/deno_task_shell/src/shell/commands/xargs.rs b/crates/deno_task_shell/src/shell/commands/xargs.rs index 4df530d..28281e6 100644 --- a/crates/deno_task_shell/src/shell/commands/xargs.rs +++ b/crates/deno_task_shell/src/shell/commands/xargs.rs @@ -178,7 +178,7 @@ fn parse_args(args: Vec) -> Result { } ArgKind::MinusShortFlag(f) => initial_args.push(format!("-{f}")), ArgKind::LongFlag(f) => initial_args.push(format!("--{f}")), - _ => continue + _ => continue, } } } diff --git a/crates/deno_task_shell/src/shell/mod.rs b/crates/deno_task_shell/src/shell/mod.rs index 5c92708..4c863db 100644 --- a/crates/deno_task_shell/src/shell/mod.rs +++ b/crates/deno_task_shell/src/shell/mod.rs @@ -13,10 +13,10 @@ pub use types::pipe; pub use types::EnvChange; pub use types::ExecuteResult; pub use types::FutureExecuteResult; +pub use types::ShellOptions; pub use types::ShellPipeReader; pub use types::ShellPipeWriter; pub use types::ShellState; -pub use types::ShellOptions; pub use commands::parse_arg_kinds; pub use commands::ArgKind; diff --git a/crates/deno_task_shell/src/shell/types.rs b/crates/deno_task_shell/src/shell/types.rs index 5873e11..2599cd4 100644 --- a/crates/deno_task_shell/src/shell/types.rs +++ b/crates/deno_task_shell/src/shell/types.rs @@ -205,7 +205,10 @@ impl ShellState { } pub fn exit_on_error(&mut self) -> bool { - matches!(self.shell_options.get(&ShellOptions::ExitOnError), Some(true)) + matches!( + self.shell_options.get(&ShellOptions::ExitOnError), + Some(true) + ) } pub fn apply_changes(&mut self, changes: &[EnvChange]) { @@ -323,7 +326,7 @@ pub enum EnvChange { /// Set the current working directory to the new Path Cd(PathBuf), /// `set -ex` - SetShellOptions(ShellOptions, bool) + SetShellOptions(ShellOptions, bool), } #[derive(Clone, Copy, Hash, PartialEq, Eq, Debug, PartialOrd)] @@ -343,7 +346,7 @@ pub const CANCELLATION_EXIT_CODE: i32 = 130; #[derive(Debug)] pub enum ExecuteResult { Exit(i32, Vec>), - Continue(i32, Vec, Vec>) + Continue(i32, Vec, Vec>), } impl ExecuteResult { diff --git a/crates/shell/src/commands/mod.rs b/crates/shell/src/commands/mod.rs index 54dd062..506cfff 100644 --- a/crates/shell/src/commands/mod.rs +++ b/crates/shell/src/commands/mod.rs @@ -8,16 +8,16 @@ use uu_ls::uumain as uu_ls; use crate::execute; pub mod date; +pub mod set; pub mod touch; pub mod uname; pub mod which; -pub mod set; pub use date::DateCommand; +pub use set::SetCommand; pub use touch::TouchCommand; pub use uname::UnameCommand; pub use which::WhichCommand; -pub use set::SetCommand; pub struct LsCommand; @@ -60,8 +60,8 @@ pub fn get_commands() -> HashMap> { ), ( "set".to_string(), - Rc::new(SetCommand) as Rc - ) + Rc::new(SetCommand) as Rc, + ), ]) } diff --git a/crates/shell/src/commands/set.rs b/crates/shell/src/commands/set.rs index 369107d..360d14f 100644 --- a/crates/shell/src/commands/set.rs +++ b/crates/shell/src/commands/set.rs @@ -4,39 +4,39 @@ use futures::future::LocalBoxFuture; use miette::bail; use miette::Result; -use deno_task_shell::{ExecuteResult, EnvChange, ShellCommandContext, ShellCommand, ArgKind, parse_arg_kinds, ShellOptions}; +use deno_task_shell::{ + parse_arg_kinds, ArgKind, EnvChange, ExecuteResult, ShellCommand, ShellCommandContext, + ShellOptions, +}; pub struct SetCommand; impl ShellCommand for SetCommand { - fn execute( - &self, - mut context: ShellCommandContext, - ) -> LocalBoxFuture<'static, ExecuteResult> { - let result = match execute_set(context.args) { - Ok((code, env_changes)) => ExecuteResult::Continue(code, env_changes, Vec::new()), - Err(err) => { - context.stderr.write_line(&format!("set: {err}")).unwrap(); - ExecuteResult::Exit(2, Vec::new()) - } - }; - Box::pin(futures::future::ready(result)) - } + fn execute(&self, mut context: ShellCommandContext) -> LocalBoxFuture<'static, ExecuteResult> { + let result = match execute_set(context.args) { + Ok((code, env_changes)) => ExecuteResult::Continue(code, env_changes, Vec::new()), + Err(err) => { + context.stderr.write_line(&format!("set: {err}")).unwrap(); + ExecuteResult::Exit(2, Vec::new()) + } + }; + Box::pin(futures::future::ready(result)) + } } fn execute_set(args: Vec) -> Result<(i32, Vec)> { - let args = parse_arg_kinds(&args); - let mut env_changes = Vec::new(); - for arg in args { - match arg { - ArgKind::MinusShortFlag('e') => { - env_changes.push(EnvChange::SetShellOptions(ShellOptions::ExitOnError, true)); - } - ArgKind::PlusShortFlag('e') => { - env_changes.push(EnvChange::SetShellOptions(ShellOptions::ExitOnError, false)); - } - _ => bail!(format!("Unsupported argument: {:?}", arg)), + let args = parse_arg_kinds(&args); + let mut env_changes = Vec::new(); + for arg in args { + match arg { + ArgKind::MinusShortFlag('e') => { + env_changes.push(EnvChange::SetShellOptions(ShellOptions::ExitOnError, true)); + } + ArgKind::PlusShortFlag('e') => { + env_changes.push(EnvChange::SetShellOptions(ShellOptions::ExitOnError, false)); + } + _ => bail!(format!("Unsupported argument: {:?}", arg)), + } } - } - Ok((0, env_changes)) + Ok((0, env_changes)) }