reactive_graph/client/instances/relations/args/
id_and_property.rs

1use crate::client::error::CommandError;
2use crate::client::error::CommandError::NotFound;
3use crate::client::instances::relations::args::id::RelationInstanceIdArgs;
4use clap::Args;
5use reactive_graph_graph::RelationInstanceId;
6
7/// CLI argument which identifies a property of a relation instance.
8#[derive(Args, Debug, Clone)]
9pub(crate) struct RelationInstanceIdAndPropertyArgs {
10    /// The id of the relation instance.
11    #[clap(flatten)]
12    pub id: RelationInstanceIdArgs,
13
14    /// The name of the property.
15    pub property_name: String,
16}
17
18impl RelationInstanceIdAndPropertyArgs {
19    pub fn not_found(&self) -> CommandError {
20        self.id.not_found()
21    }
22
23    pub fn property_not_found(&self) -> CommandError {
24        let id: RelationInstanceId = self.into();
25        NotFound(format!("The relation instance with the id {} has no property {}", id, &self.property_name))
26    }
27}
28
29impl From<&RelationInstanceIdAndPropertyArgs> for RelationInstanceId {
30    fn from(args: &RelationInstanceIdAndPropertyArgs) -> Self {
31        RelationInstanceId::from(&args.id)
32    }
33}