rkubectl_kubeapi/
namespace.rs

1#[derive(Clone, Debug, Default)]
2pub enum Namespace {
3    All,
4    #[default]
5    Default,
6    Namespace(String),
7}
8
9impl Namespace {
10    pub fn new(all_namespaces: bool, namespace: Option<&str>) -> Self {
11        let namespace = namespace.map(ToString::to_string);
12        match (all_namespaces, namespace) {
13            (true, _) => Self::All,
14            (false, None) => Self::Default,
15            (false, Some(namespace)) => Self::Namespace(namespace),
16        }
17    }
18
19    pub fn namespace(&self) -> Option<String> {
20        match self {
21            Self::All => None,
22            Self::Default => None,
23            Self::Namespace(namespace) => Some(namespace.clone()),
24        }
25    }
26}