2023-07-06 21:09:13 +00:00
|
|
|
use crate::cli::abstraction::OptionalDatabaseConnectionArguments;
|
2024-01-20 21:53:59 +00:00
|
|
|
use crate::env::RELEASE;
|
2022-02-16 23:45:23 +00:00
|
|
|
use crate::err::Error;
|
2023-07-06 21:09:13 +00:00
|
|
|
use clap::Args;
|
|
|
|
use surrealdb::engine::any::connect;
|
2020-06-29 15:36:01 +00:00
|
|
|
|
2023-07-06 21:09:13 +00:00
|
|
|
#[derive(Args, Debug)]
|
|
|
|
pub struct VersionCommandArguments {
|
|
|
|
#[command(flatten)]
|
|
|
|
conn: OptionalDatabaseConnectionArguments,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn init(
|
|
|
|
VersionCommandArguments {
|
|
|
|
conn: OptionalDatabaseConnectionArguments {
|
|
|
|
endpoint,
|
|
|
|
},
|
|
|
|
}: VersionCommandArguments,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
// Initialize opentelemetry and logging
|
2023-07-19 14:35:56 +00:00
|
|
|
crate::telemetry::builder().with_log_level("error").init();
|
2023-07-06 21:09:13 +00:00
|
|
|
// Print server version if endpoint supplied else CLI version
|
|
|
|
if let Some(e) = endpoint {
|
|
|
|
// Print remote server version
|
|
|
|
println!("{}", get_server_version_string(e).await?);
|
|
|
|
} else {
|
|
|
|
// Print local CLI version
|
2024-01-20 21:53:59 +00:00
|
|
|
println!("{}", *RELEASE);
|
2023-07-06 21:09:13 +00:00
|
|
|
}
|
2020-06-29 15:36:01 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2023-07-06 21:09:13 +00:00
|
|
|
|
|
|
|
async fn get_server_version_string(endpoint: String) -> Result<String, Error> {
|
|
|
|
// Connect to the database engine
|
|
|
|
let client = connect(endpoint).await?;
|
|
|
|
// Query database version info
|
|
|
|
let server_version = client.version().await?;
|
|
|
|
// Convert version info to formatted string
|
|
|
|
Ok(server_version.to_string())
|
|
|
|
}
|