Skip to main content

oxilean_codegen/bash_backend/
bashcondition_traits.rs

1//! # BashCondition - Trait Implementations
2//!
3//! This module contains trait implementations for `BashCondition`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::types::BashCondition;
12use std::fmt;
13
14impl fmt::Display for BashCondition {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            BashCondition::FileExists(e) => write!(f, "[[ -e {} ]]", e),
18            BashCondition::IsFile(e) => write!(f, "[[ -f {} ]]", e),
19            BashCondition::IsDir(e) => write!(f, "[[ -d {} ]]", e),
20            BashCondition::NonEmpty(e) => write!(f, "[[ -n {} ]]", e),
21            BashCondition::Empty(e) => write!(f, "[[ -z {} ]]", e),
22            BashCondition::StrEq(a, b) => write!(f, "[[ {} == {} ]]", a, b),
23            BashCondition::StrNe(a, b) => write!(f, "[[ {} != {} ]]", a, b),
24            BashCondition::StrLt(a, b) => write!(f, "[[ {} < {} ]]", a, b),
25            BashCondition::ArithLt(a, b) => write!(f, "(( {} < {} ))", a, b),
26            BashCondition::ArithEq(a, b) => write!(f, "(( {} == {} ))", a, b),
27            BashCondition::And(a, b) => write!(f, "[[ {} && {} ]]", a, b),
28            BashCondition::Or(a, b) => write!(f, "[[ {} || {} ]]", a, b),
29            BashCondition::Not(c) => write!(f, "! {}", c),
30            BashCondition::Raw(s) => write!(f, "{}", s),
31        }
32    }
33}