reactive_graph_client/client/args/
connection.rs

1use clap::Parser;
2use reactive_graph_remotes_model::DEFAULT_ENDPOINT_DYNAMIC_GRAPH;
3use reactive_graph_remotes_model::DEFAULT_ENDPOINT_GRAPHQL;
4use reactive_graph_remotes_model::DEFAULT_ENDPOINT_PLUGIN;
5use reactive_graph_remotes_model::DEFAULT_ENDPOINT_RUNTIME;
6use reactive_graph_remotes_model::DEFAULT_HOSTNAME;
7use reactive_graph_remotes_model::DEFAULT_PORT;
8use reactive_graph_remotes_model::InstanceAddress;
9
10#[derive(Parser, Debug, Clone)]
11pub struct ClientConnectionArguments {
12    /// The hostname to connect to.
13    #[arg(long)]
14    client_hostname: Option<String>,
15
16    /// The port to connect to.
17    #[arg(long)]
18    client_port: Option<u16>,
19
20    /// If true, connects via HTTPS.
21    #[arg(long)]
22    client_secure: Option<bool>,
23
24    /// The endpoint to use.
25    #[arg(long)]
26    endpoint_graphql: Option<String>,
27
28    /// The endpoint to use.
29    #[arg(long)]
30    endpoint_dynamic_graph: Option<String>,
31
32    /// The endpoint to use.
33    #[arg(long)]
34    endpoint_runtime: Option<String>,
35
36    /// The endpoint to use.
37    #[arg(long)]
38    endpoint_plugins: Option<String>,
39
40    /// The authentication token.
41    #[arg(long)]
42    bearer: Option<String>,
43}
44
45impl From<&ClientConnectionArguments> for InstanceAddress {
46    fn from(args: &ClientConnectionArguments) -> Self {
47        InstanceAddress::builder()
48            .hostname(args.client_hostname.clone().unwrap_or(DEFAULT_HOSTNAME.to_string()))
49            .port(args.client_port.unwrap_or(DEFAULT_PORT))
50            .secure(args.client_secure.unwrap_or_default())
51            .endpoint_graphql(args.endpoint_graphql.clone().unwrap_or(DEFAULT_ENDPOINT_GRAPHQL.to_string()))
52            .endpoint_dynamic_graph(args.endpoint_dynamic_graph.clone().unwrap_or(DEFAULT_ENDPOINT_DYNAMIC_GRAPH.to_string()))
53            .endpoint_runtime(args.endpoint_runtime.clone().unwrap_or(DEFAULT_ENDPOINT_RUNTIME.to_string()))
54            .endpoint_plugin(args.endpoint_plugins.clone().unwrap_or(DEFAULT_ENDPOINT_PLUGIN.to_string()))
55            .bearer(args.bearer.clone())
56            .build()
57    }
58}