Skip to main content

caretta_sync_cli/cli/args/
device_identifier.rs

1use clap::Args;
2use iroh::PublicKey;
3use iroh_tickets::endpoint::EndpointTicket;
4use mtid::Dtid;
5
6#[derive(Args, Clone, Debug)]
7#[group(multiple = false, required = true)]
8pub struct DeviceIdentifierArgs {
9    #[arg(long)]
10    device_id: Option<Dtid>,
11    #[arg(long)]
12    endpoint_id: Option<PublicKey>,
13    #[arg(long)]
14    endpoint_ticket: Option<EndpointTicket>,
15}
16
17impl From<DeviceIdentifierArgs> for caretta_sync_core::proto::api::device::Identifier {
18    fn from(value: DeviceIdentifierArgs) -> Self {
19        use caretta_sync_core::proto::api::device::identifier::Value;
20        Self {
21            value: Some(
22                match (value.device_id, value.endpoint_id, value.endpoint_ticket) {
23                    (Some(x), None, None) => Value::Id(x.into()),
24                    (None, Some(x), None) => Value::EndpointId(x.into()),
25                    (None, None, Some(x)) => Value::EndpointTicket(x.into()),
26                    (_, _, _) => unreachable!("The parsed argument must be one."),
27                },
28            ),
29        }
30    }
31}