Skip to content

Commit

Permalink
run fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Nov 27, 2024
1 parent 7673439 commit f90b8ed
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 39 deletions.
4 changes: 3 additions & 1 deletion crates/deno_task_shell/src/shell/commands/mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ fn parse_args(args: Vec<String>) -> Result<MkdirFlags> {
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()?,
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/deno_task_shell/src/shell/commands/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ fn parse_args(args: Vec<String>) -> Result<RmFlags> {
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()?,
}
}

Expand Down
4 changes: 3 additions & 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,9 @@ fn parse_args(args: Vec<String>) -> Result<u64> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/deno_task_shell/src/shell/commands/xargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn parse_args(args: Vec<String>) -> Result<XargsFlags> {
}
ArgKind::MinusShortFlag(f) => initial_args.push(format!("-{f}")),
ArgKind::LongFlag(f) => initial_args.push(format!("--{f}")),
_ => continue
_ => continue,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/deno_task_shell/src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions crates/deno_task_shell/src/shell/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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)]
Expand All @@ -343,7 +346,7 @@ pub const CANCELLATION_EXIT_CODE: i32 = 130;
#[derive(Debug)]
pub enum ExecuteResult {
Exit(i32, Vec<JoinHandle<i32>>),
Continue(i32, Vec<EnvChange>, Vec<JoinHandle<i32>>)
Continue(i32, Vec<EnvChange>, Vec<JoinHandle<i32>>),
}

impl ExecuteResult {
Expand Down
8 changes: 4 additions & 4 deletions crates/shell/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -60,8 +60,8 @@ pub fn get_commands() -> HashMap<String, Rc<dyn ShellCommand>> {
),
(
"set".to_string(),
Rc::new(SetCommand) as Rc<dyn ShellCommand>
)
Rc::new(SetCommand) as Rc<dyn ShellCommand>,
),
])
}

Expand Down
54 changes: 27 additions & 27 deletions crates/shell/src/commands/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Result<(i32, Vec<EnvChange>)> {
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))
}

0 comments on commit f90b8ed

Please sign in to comment.