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
use crate::common::Identifier;
use std::fmt::{Display, Formatter};

/// https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/cqlListRoles.html
#[derive(PartialEq, Debug, Clone)]
pub struct ListRole {
    /// List roles only for this role.
    pub of: Option<Identifier>,
    /// if true the NORECURSIVE option has been set.
    pub no_recurse: bool,
}

impl Display for ListRole {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        let mut s: String = "".to_string();
        if let Some(of) = &self.of {
            s = " OF ".to_string();
            s.push_str(of.to_string().as_str());
        }
        write!(
            f,
            "LIST ROLES{}{}",
            s.as_str(),
            if self.no_recurse { " NORECURSIVE" } else { "" }
        )
    }
}