cargo_msrv/reporter/event/
subcommand_init.rs

1use crate::reporter::event::Message;
2use crate::Event;
3
4#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
5#[serde(rename_all = "snake_case")]
6pub struct SubcommandInit {
7    subcommand_id: &'static str,
8}
9
10impl SubcommandInit {
11    pub fn new(subcommand_id: &'static str) -> Self {
12        Self { subcommand_id }
13    }
14
15    pub fn subcommand_id(&self) -> &'static str {
16        self.subcommand_id
17    }
18}
19
20impl From<SubcommandInit> for Event {
21    fn from(it: SubcommandInit) -> Self {
22        Message::SubcommandInit(it).into()
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use crate::reporter::event::Message;
29    use crate::reporter::TestReporterWrapper;
30    use crate::{Event, SubcommandInit};
31    use storyteller::EventReporter;
32
33    #[test]
34    fn reported_action() {
35        let reporter = TestReporterWrapper::default();
36        let event = SubcommandInit::new("find");
37
38        reporter.get().report_event(event.clone()).unwrap();
39
40        assert_eq!(
41            reporter.wait_for_events(),
42            vec![Event::unscoped(Message::SubcommandInit(event)),]
43        );
44    }
45}