1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use serde::{Deserialize, Serialize};

use super::Merge;

/// Configure log capturing.
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Default, schemars::JsonSchema)]
pub struct CapabilityLoggingV1 {
    /// Enable log capture.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enabled: Option<bool>,

    /// Capture the stdout stream.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub capture_stdout: Option<bool>,

    /// Capture the stderr stream.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub capture_stderr: Option<bool>,
}

impl CapabilityLoggingV1 {
    pub fn enabled(&self) -> bool {
        self.enabled.unwrap_or_default()
    }

    pub fn capture_stdout(&self) -> bool {
        self.capture_stdout.unwrap_or_default()
    }

    pub fn capture_stderr(&self) -> bool {
        self.capture_stderr.unwrap_or_default()
    }
}

impl Merge for CapabilityLoggingV1 {
    fn merge_extend(self, other: &Self) -> Self {
        Self {
            enabled: self.enabled.merge_extend(&other.enabled),
            capture_stdout: self.capture_stdout.merge_extend(&other.capture_stdout),
            capture_stderr: self.capture_stderr.merge_extend(&other.capture_stderr),
        }
    }
}