reactive_graph_command_model/reactive_graph/command/
command.rs1#![allow(dead_code, unused)]
5#![cfg_attr(rustfmt, rustfmt_skip)]
6
7#[cfg_attr(rustfmt, rustfmt_skip)]
9pub const COMMAND_NAMESPACE: &str = "reactive_graph::command::Command";
10
11pub static COMMAND: std::sync::LazyLock<reactive_graph_graph::ComponentTypeId> = std::sync::LazyLock::new(||
18std::str::FromStr::from_str(COMMAND_NAMESPACE).unwrap());
19
20#[allow(non_camel_case_types)]
22#[derive(Debug, PartialEq, PartialOrd, Eq, Hash, Clone)]
23pub enum CommandProperties {
24
25 ARGS,
36
37 CMD_IGNORE,
48
49 CMD_RESULT,
60
61 COMMAND,
72
73 HELP,
84
85 NAMESPACE,
96}
97impl CommandProperties {
98 pub fn len() -> usize {
99 6usize
100 }
101
102 pub fn property_types() -> reactive_graph_graph::PropertyTypes {
103 let property_types = reactive_graph_graph::PropertyTypes::new();
104 property_types.push(CommandProperties::ARGS);
105 property_types.push(CommandProperties::CMD_IGNORE);
106 property_types.push(CommandProperties::CMD_RESULT);
107 property_types.push(CommandProperties::COMMAND);
108 property_types.push(CommandProperties::HELP);
109 property_types.push(CommandProperties::NAMESPACE);
110 property_types
111 }
112}
113
114impl AsRef<str> for CommandProperties {
115 #[inline]
116 fn as_ref(&self) -> &str {
117 match *self {
118 CommandProperties::ARGS => "args",
119 CommandProperties::CMD_IGNORE => "cmd_ignore",
120 CommandProperties::CMD_RESULT => "cmd_result",
121 CommandProperties::COMMAND => "command",
122 CommandProperties::HELP => "help",
123 CommandProperties::NAMESPACE => "namespace",
124 }
125 }
126}
127
128impl From<CommandProperties> for &'static str {
129 #[inline]
130 fn from(properties: CommandProperties) -> &'static str {
131 match properties {
132 CommandProperties::ARGS => "args",
133 CommandProperties::CMD_IGNORE => "cmd_ignore",
134 CommandProperties::CMD_RESULT => "cmd_result",
135 CommandProperties::COMMAND => "command",
136 CommandProperties::HELP => "help",
137 CommandProperties::NAMESPACE => "namespace",
138 }
139 }
140}
141
142impl From<CommandProperties> for String {
143 #[inline]
144 fn from(properties: CommandProperties) -> String {
145 match properties {
146 CommandProperties::ARGS => "args".to_owned(),
147 CommandProperties::CMD_IGNORE => "cmd_ignore".to_owned(),
148 CommandProperties::CMD_RESULT => "cmd_result".to_owned(),
149 CommandProperties::COMMAND => "command".to_owned(),
150 CommandProperties::HELP => "help".to_owned(),
151 CommandProperties::NAMESPACE => "namespace".to_owned(),
152 }
153 }
154}
155
156impl From<CommandProperties> for reactive_graph_graph::PropertyType {
157 #[inline]
158 fn from(properties: CommandProperties) -> reactive_graph_graph::PropertyType {
159 match properties {
160 CommandProperties::ARGS => {
161 reactive_graph_graph::PropertyType::new_with_all(
162 "args",
163 "The command arguments",
164 reactive_graph_graph::DataType::Array,
165 reactive_graph_graph::SocketType::None,
166 reactive_graph_graph::Mutability::Immutable,
167 reactive_graph_graph::Extensions::new(),
168 )
169 }
170 CommandProperties::CMD_IGNORE => {
171 reactive_graph_graph::PropertyType::new_with_all(
172 "cmd_ignore",
173 "blah",
174 reactive_graph_graph::DataType::Any,
175 reactive_graph_graph::SocketType::None,
176 reactive_graph_graph::Mutability::Mutable,
177 reactive_graph_graph::Extensions::new(),
178 )
179 }
180 CommandProperties::CMD_RESULT => {
181 reactive_graph_graph::PropertyType::new_with_all(
182 "cmd_result",
183 "The result of the command",
184 reactive_graph_graph::DataType::Any,
185 reactive_graph_graph::SocketType::Output,
186 reactive_graph_graph::Mutability::Immutable,
187 reactive_graph_graph::Extensions::new(),
188 )
189 }
190 CommandProperties::COMMAND => {
191 reactive_graph_graph::PropertyType::new_with_all(
192 "command",
193 "The command name",
194 reactive_graph_graph::DataType::String,
195 reactive_graph_graph::SocketType::None,
196 reactive_graph_graph::Mutability::Immutable,
197 reactive_graph_graph::Extensions::new(),
198 )
199 }
200 CommandProperties::HELP => {
201 reactive_graph_graph::PropertyType::new_with_all(
202 "help",
203 "Help text which explains the command.",
204 reactive_graph_graph::DataType::String,
205 reactive_graph_graph::SocketType::None,
206 reactive_graph_graph::Mutability::Immutable,
207 reactive_graph_graph::Extensions::new(),
208 )
209 }
210 CommandProperties::NAMESPACE => {
211 reactive_graph_graph::PropertyType::new_with_all(
212 "namespace",
213 "The command namespace",
214 reactive_graph_graph::DataType::String,
215 reactive_graph_graph::SocketType::None,
216 reactive_graph_graph::Mutability::Immutable,
217 reactive_graph_graph::Extensions::new(),
218 )
219 }
220 }
221 }
222}
223
224pub struct CommandPropertiesIterator(Option<CommandProperties>);
225
226impl CommandProperties {
227 pub fn into_iter() -> CommandPropertiesIterator {
228 CommandPropertiesIterator(None)
229 }
230}
231
232impl Iterator for CommandPropertiesIterator {
233 type Item = CommandProperties;
234 fn next(&mut self) -> Option<Self::Item> {
235 self.0 = match self.0 {
236 None => Some(CommandProperties::ARGS),
237 Some(CommandProperties::ARGS) => Some(CommandProperties::CMD_IGNORE),
238 Some(CommandProperties::CMD_IGNORE) => Some(CommandProperties::CMD_RESULT),
239 Some(CommandProperties::CMD_RESULT) => Some(CommandProperties::COMMAND),
240 Some(CommandProperties::COMMAND) => Some(CommandProperties::HELP),
241 Some(CommandProperties::HELP) => Some(CommandProperties::NAMESPACE),
242 Some(CommandProperties::NAMESPACE) => None,
243 };
244 self.0.clone()
245 }
246}
247
248impl IntoIterator for CommandProperties {
249 type Item = CommandProperties;
250 type IntoIter = CommandPropertiesIterator;
251 fn into_iter(self) -> Self::IntoIter {
252 CommandPropertiesIterator(None)
253 }
254}
255
256impl core::fmt::Display for CommandProperties {
257 fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
258 match *self {
259 CommandProperties::ARGS => core::fmt::Display::fmt("args", f),
260 CommandProperties::CMD_IGNORE => core::fmt::Display::fmt("cmd_ignore", f),
261 CommandProperties::CMD_RESULT => core::fmt::Display::fmt("cmd_result", f),
262 CommandProperties::COMMAND => core::fmt::Display::fmt("command", f),
263 CommandProperties::HELP => core::fmt::Display::fmt("help", f),
264 CommandProperties::NAMESPACE => core::fmt::Display::fmt("namespace", f),
265 }
266 }
267}
268
269pub static COMMAND_EXTENSIONS: std::sync::LazyLock<reactive_graph_graph::Extensions> = std::sync::LazyLock::new(||
271{ reactive_graph_graph::Extensions::new() });
272
273pub static COMMAND_TYPE: std::sync::LazyLock<reactive_graph_graph::Component> = std::sync::LazyLock::new(||
274{
275 reactive_graph_graph::Component::builder()
276 .ty(core::ops::Deref::deref(&COMMAND))
277 .description(
278 "A command which can be executed. The command has a name and can have command arguments.",
279 )
280 .properties(CommandProperties::property_types())
281 .build()
282});
283
284pub trait Command {
308
309 fn args(&self) -> Vec<serde_json::Value>;
320
321 fn cmd_ignore(&self) -> serde_json::Value;
332
333 fn set_cmd_ignore(&mut self, cmd_ignore: serde_json::Value);
344
345 fn cmd_result(&self) -> serde_json::Value;
356
357 fn command(&self) -> String;
368
369 fn help(&self) -> String;
380
381 fn namespace(&self) -> String;
392}