From 134a50d8ce663b2a74366566ff7201c21aaa7304 Mon Sep 17 00:00:00 2001 From: kruserr <46799551+kruserr@users.noreply.github.com> Date: Sat, 12 Oct 2024 14:34:59 +0000 Subject: [PATCH] style: fmt --- i6-shell/src/lang.rs | 80 ++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/i6-shell/src/lang.rs b/i6-shell/src/lang.rs index cfb6d6a..35aa94e 100644 --- a/i6-shell/src/lang.rs +++ b/i6-shell/src/lang.rs @@ -237,39 +237,45 @@ impl Interpreter for DefaultInterpreter { _ => eprintln!("Unknown operator"), }, ASTNode::Pipe { left, right } => { - let first_command_output = if let ASTNode::Command { name, args } = *left { - let args: Vec = args - .into_iter() - .map(|arg| { - if let ASTNode::Argument { value } = arg { - value - } else { - eprintln!("Invalid syntax"); - "".to_owned() - } - }) - .collect(); - - let args_str = &args.join(" "); - - if let Some(custom_command) = custom_commands.get(&name) { - custom_command.run(args_str).unwrap_or_default() - } else if let Ok(lock) = crate::command::DEFAULT_COMMANDS.lock() { - if let Ok(commands) = lock.as_ref() { - if let Some(command) = commands.get(&name) { - command.run(args_str).unwrap_or_default() - } else { - { - let child = std::process::Command::new(&name).args(args).spawn(); - - match child { - Ok(mut child) => { - child.wait().unwrap(); + let first_command_output = + if let ASTNode::Command { name, args } = *left { + let args: Vec = args + .into_iter() + .map(|arg| { + if let ASTNode::Argument { value } = arg { + value + } else { + eprintln!("Invalid syntax"); + "".to_owned() + } + }) + .collect(); + + let args_str = &args.join(" "); + + if let Some(custom_command) = custom_commands.get(&name) { + custom_command.run(args_str).unwrap_or_default() + } else if let Ok(lock) = crate::command::DEFAULT_COMMANDS.lock() { + if let Ok(commands) = lock.as_ref() { + if let Some(command) = commands.get(&name) { + command.run(args_str).unwrap_or_default() + } else { + { + let child = + std::process::Command::new(&name).args(args).spawn(); + + match child { + Ok(mut child) => { + child.wait().unwrap(); + } + Err(e) => eprintln!("{}", e), } - Err(e) => eprintln!("{}", e), } - } + return; + } + } else { + eprintln!("Failed to acquire lock"); return; } } else { @@ -277,12 +283,8 @@ impl Interpreter for DefaultInterpreter { return; } } else { - eprintln!("Failed to acquire lock"); return; - } - } else { - return; - }; + }; if let ASTNode::Command { name, args } = *right { let args: Vec = args @@ -312,7 +314,10 @@ impl Interpreter for DefaultInterpreter { if let Ok(commands) = lock.as_ref() { if let Some(command) = commands.get(&name) { let _ = command - .run(&format!("\"{}\" \"{}\"", args_str, first_command_output)) + .run(&format!( + "\"{}\" \"{}\"", + args_str, first_command_output + )) .map(|output| { if !output.is_empty() { println!("{output}"); @@ -321,7 +326,8 @@ impl Interpreter for DefaultInterpreter { .map_err(|e| eprintln!("{e}")); } else { { - let child = std::process::Command::new(&name).args(args).spawn(); + let child = + std::process::Command::new(&name).args(args).spawn(); match child { Ok(mut child) => {