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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
//! ref: composer/vendor/symfony/console/Descriptor/Descriptor.php
use crate::symfony::console::application::Application;
use crate::symfony::console::command::command::Command;
use crate::symfony::console::descriptor::descriptor_interface::{
DescribableObject, DescriptorInterface,
};
use crate::symfony::console::input::input_argument::InputArgument;
use crate::symfony::console::input::input_definition::InputDefinition;
use crate::symfony::console::input::input_option::InputOption;
use crate::symfony::console::output::output_interface::OutputInterface;
use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
/// @internal
pub trait Descriptor: DescriptorInterface {
fn output(&self) -> std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>;
fn set_output(&mut self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>);
fn describe(
&mut self,
output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
object: DescribableObject,
options: IndexMap<String, PhpMixed>,
) -> anyhow::Result<()> {
self.set_output(output);
// PHP dispatches via `$object instanceof ...`; the explicit `DescribableObject` enum makes
// that dispatch a `match`.
match object {
DescribableObject::InputArgument(argument) => {
self.describe_input_argument(&argument, options)?;
}
DescribableObject::InputOption(option) => {
self.describe_input_option(&option, options)?;
}
DescribableObject::InputDefinition(definition) => {
self.describe_input_definition(&definition, options)?;
}
DescribableObject::Command(command) => {
self.describe_command(&mut *command.borrow_mut(), options)?;
}
DescribableObject::Application(application) => {
self.describe_application(application, options)?;
}
}
Ok(())
}
/// Writes content to output.
fn write(&self, content: &str, decorated: bool) {
self.output().borrow().write(
&[content.to_string()],
false,
if decorated {
crate::symfony::console::output::output_interface::OUTPUT_NORMAL
} else {
crate::symfony::console::output::output_interface::OUTPUT_RAW
},
);
}
/// Describes an InputArgument instance.
fn describe_input_argument(
&mut self,
argument: &InputArgument,
options: IndexMap<String, PhpMixed>,
) -> anyhow::Result<()>;
/// Describes an InputOption instance.
fn describe_input_option(
&mut self,
option: &InputOption,
options: IndexMap<String, PhpMixed>,
) -> anyhow::Result<()>;
/// Describes an InputDefinition instance.
fn describe_input_definition(
&mut self,
definition: &InputDefinition,
options: IndexMap<String, PhpMixed>,
) -> anyhow::Result<()>;
/// Describes a Command instance.
fn describe_command(
&mut self,
command: &mut dyn Command,
options: IndexMap<String, PhpMixed>,
) -> anyhow::Result<()>;
/// Describes an Application instance.
fn describe_application(
&mut self,
application: std::rc::Rc<std::cell::RefCell<dyn Application>>,
options: IndexMap<String, PhpMixed>,
) -> anyhow::Result<()>;
}
|