reactive_graph_client/client/
mod.rs

1use std::process::exit;
2
3use colored::Colorize;
4
5use reactive_graph_client::ReactiveGraphClient;
6
7use crate::client::args::ClientArguments;
8use crate::client::handler::handle_command;
9use crate::client::repl::repl;
10
11pub mod args;
12pub mod commands;
13pub mod error;
14pub mod handler;
15pub mod instances;
16pub mod introspection;
17pub mod output_format;
18pub mod repl;
19pub mod result;
20pub mod system;
21pub mod types;
22
23#[tokio::main]
24pub async fn client(args: ClientArguments) {
25    let client = match ReactiveGraphClient::new(&args.connection) {
26        Ok(client) => client,
27        Err(e) => {
28            eprintln!("{}: {}", "Failed to create client".red(), e);
29            exit(255);
30        }
31    };
32    // If no command was given, enter the REPL mode
33    let Some(command) = args.commands else {
34        match repl(&client).await {
35            Ok(_) => exit(0),
36            Err(exit_code) => exit(exit_code),
37        }
38    };
39    // If a command was given, handle command
40    match handle_command(&client, command).await {
41        Ok(response) => {
42            println!("{response}");
43            exit(0)
44        }
45        Err(e) => {
46            eprintln!("{}: {}", "Command failed with error".red(), e);
47            exit(e.exit_code())
48        }
49    }
50}