aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/attribute/as_command.rs
blob: c742fd538e989f9566238e860831e56934b2d14d (plain)
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
/// Service tag to autoconfigure commands.
///
/// PHP attribute: #[\Attribute(\Attribute::TARGET_CLASS)]
#[derive(Debug)]
pub struct AsCommand {
    pub name: String,
    pub description: Option<String>,
}

impl AsCommand {
    pub fn new(
        name: String,
        description: Option<String>,
        aliases: Vec<String>,
        hidden: bool,
    ) -> Self {
        let mut this = Self { name, description };

        if !hidden && aliases.is_empty() {
            return this;
        }

        let mut name: Vec<String> = this.name.split('|').map(|s| s.to_string()).collect();
        name.extend(aliases);

        if hidden && "" != name[0] {
            name.insert(0, String::new());
        }

        this.name = name.join("|");

        this
    }
}