asterust-junos 0.5.4

Typed Juniper JunOS config views (interfaces, protocols, routing instances and options, policy options, firewall filters, class of service, system, services) extracted from an asterust config tree.
Documentation
//! `tca`
//! `interfaces <name> { optics-options { tca ... } }` and `interfaces <name> { otn-options { tca ... } }`.
//!
//! # See also
//!
//! - [tca](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/tca-edit-interfaces-otn-options.html)

use crate::split_keyword;

/// A threshold crossing alert, `tca <identifier> (enable-tca | no-enable-tca) (threshold <n> | threshold-24hrs <n>)`.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Tca {
    /// The alert, e.g. `"odu-bbe"`.
    pub identifier: String,
    /// `Some(true)` for `enable-tca`, `Some(false)` for `no-enable-tca`.
    pub enabled: Option<bool>,
    pub threshold: Option<String>,
    pub threshold_24hrs: Option<String>,
}

/// Parses the argument of a `tca` statement.
pub(super) fn parse_tca(arg: &str) -> Tca {
    let (identifier, rest) = split_keyword(arg);
    let words: Vec<&str> = rest.split_whitespace().collect();
    let enabled = if words.contains(&"enable-tca") {
        Some(true)
    } else if words.contains(&"no-enable-tca") {
        Some(false)
    } else {
        None
    };
    Tca {
        identifier: identifier.to_string(),
        enabled,
        threshold: crate::value_after(&words, "threshold"),
        threshold_24hrs: crate::value_after(&words, "threshold-24hrs"),
    }
}