reactive_graph/client/types/extension/
args.rs

1use crate::client::types::entities::args::parse_entity_ty;
2use clap::Args;
3use reactive_graph_graph::EntityTypeId;
4use reactive_graph_graph::Extension;
5use reactive_graph_graph::ExtensionTypeId;
6use serde_json::Value;
7use std::error::Error;
8use std::str::FromStr;
9
10pub fn parse_extension_ty(namespace: &str) -> Result<ExtensionTypeId, Box<dyn Error + Send + Sync + 'static>> {
11    Ok(ExtensionTypeId::from_str(namespace).map_err(Box::new)?)
12}
13
14/// The property type.
15#[derive(Args, Debug, Clone)]
16pub(crate) struct ExtensionDefinitionArgs {
17    /// The fully qualified namespace of the extension.
18    #[clap(name = "extension_type", value_parser = parse_extension_ty)]
19    pub extension_ty: ExtensionTypeId,
20
21    /// The fully qualified namespace of the entity type which is the type constraint of the extension.
22    #[clap(long, name = "extension_entity_type", value_parser = parse_entity_ty)]
23    pub entity_ty: Option<EntityTypeId>,
24
25    /// Textual description of the extension.
26    #[clap(long)]
27    pub description: Option<String>,
28
29    /// The extension as JSON representation.
30    pub extension: Value,
31}
32
33impl From<&ExtensionDefinitionArgs> for Extension {
34    fn from(args: &ExtensionDefinitionArgs) -> Self {
35        Self {
36            ty: args.extension_ty.clone(),
37            entity_ty: args.entity_ty.clone(),
38            description: args.description.clone().unwrap_or_default(),
39            extension: args.extension.clone(),
40        }
41    }
42}