aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/plugin/command_event.rs
blob: ca63461d5c1955ac5fda0559aece8f032064f7de (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! ref: composer/src/Composer/Plugin/CommandEvent.php

use crate::event_dispatcher::Event;
use crate::event_dispatcher::EventInterface;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::PhpMixed;

#[derive(Debug)]
pub struct CommandEvent {
    inner: Event,
    command_name: String,
    input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
    output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
}

impl CommandEvent {
    pub fn new(
        name: &str,
        command_name: &str,
        input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
        output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
    ) -> Self {
        Self::new6(name, command_name, input, output, vec![], IndexMap::new())
    }

    pub fn new6(
        name: &str,
        command_name: &str,
        input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
        output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
        args: Vec<String>,
        flags: IndexMap<String, PhpMixed>,
    ) -> Self {
        let inner = Event::new(name.to_string(), args, flags);
        Self {
            inner,
            command_name: command_name.to_string(),
            input,
            output,
        }
    }

    pub fn get_input(&self) -> std::rc::Rc<std::cell::RefCell<dyn InputInterface>> {
        self.input.clone()
    }

    pub fn get_output(&self) -> std::rc::Rc<std::cell::RefCell<dyn OutputInterface>> {
        self.output.clone()
    }

    pub fn get_name(&self) -> &str {
        self.inner.get_name()
    }

    pub fn get_command_name(&self) -> &str {
        &self.command_name
    }
}

impl EventInterface for CommandEvent {
    fn get_name(&self) -> &str {
        self.inner.get_name()
    }

    fn get_arguments(&self) -> &Vec<String> {
        self.inner.get_arguments()
    }

    fn get_flags(&self) -> &IndexMap<String, PhpMixed> {
        self.inner.get_flags()
    }

    fn is_propagation_stopped(&self) -> bool {
        self.inner.is_propagation_stopped()
    }

    fn stop_propagation(&mut self) {
        self.inner.stop_propagation();
    }
}