use super::*; use std::marker::PhantomData; #[derive(Debug)] pub(crate) struct OutputContains> { _s: PhantomData, output_of: Output, contains: &'static str, } impl> OutputContains { pub(crate) fn new(output_of: Output, contains: &'static str) -> Self { Self { _s: PhantomData, output_of, contains, } } } impl> Expression for OutputContains { fn write_shell(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result { self.output_of.write_shell(writer)?; write!(writer, " | grep {}", Zsh::shell_escape(self.contains)) } } impl> Expression for OutputContains { fn write_shell(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result { self.output_of.write_shell(writer)?; write!(writer, " | grep {}", Bash::shell_escape(self.contains)) } } impl> Expression for OutputContains { fn write_shell(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result { self.output_of.write_shell(writer)?; write!(writer, " | grep {}", Fish::shell_escape(self.contains)) } } impl> Expression for OutputContains { fn write_shell(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result { // $($__out__ = (fnm ls | findstr 6.11.3); if ($LASTEXITCODE -ne 0) { "WELP" } else { $__out__ }) write!(writer, "$(")?; { write!(writer, "$__out__ = $(")?; { self.output_of.write_shell(writer)?; write!( writer, " | Select-String {}", PowerShell::shell_escape(self.contains) )?; } write!(writer, "); ")?; write!(writer, "echo $__out__; ")?; write!(writer, "if ($__out__ -eq $null)")?; write!(writer, "{{ exit 1 }} ")?; write!(writer, "else {{ $__out__ }}")?; } write!(writer, ")")?; Ok(()) } }