Feature: Add short alias v
for surreal version
command (#3334)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
f090ff3360
commit
ae66978e44
4 changed files with 33 additions and 12 deletions
|
@ -13,6 +13,7 @@ pub(crate) mod validator;
|
|||
mod version;
|
||||
|
||||
use crate::cnf::LOGO;
|
||||
use crate::env::RELEASE;
|
||||
use backup::BackupCommandArguments;
|
||||
use clap::{Parser, Subcommand};
|
||||
pub use config::CF;
|
||||
|
@ -42,8 +43,8 @@ We would love it if you could star the repository (https://github.com/surrealdb/
|
|||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "SurrealDB command-line interface and server", bin_name = "surreal")]
|
||||
#[command(about = INFO, before_help = LOGO)]
|
||||
#[command(disable_version_flag = true, arg_required_else_help = true)]
|
||||
#[command(version = RELEASE.as_str(), about = INFO, before_help = LOGO)]
|
||||
#[command(disable_version_flag = false, arg_required_else_help = true)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::cli::abstraction::OptionalDatabaseConnectionArguments;
|
||||
use crate::env::release;
|
||||
use crate::env::RELEASE;
|
||||
use crate::err::Error;
|
||||
use clap::Args;
|
||||
use surrealdb::engine::any::connect;
|
||||
|
@ -25,7 +25,7 @@ pub async fn init(
|
|||
println!("{}", get_server_version_string(e).await?);
|
||||
} else {
|
||||
// Print local CLI version
|
||||
println!("{}", release());
|
||||
println!("{}", *RELEASE);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
12
src/env/mod.rs
vendored
12
src/env/mod.rs
vendored
|
@ -1,15 +1,15 @@
|
|||
use crate::cnf::PKG_VERSION;
|
||||
use crate::err::Error;
|
||||
use once_cell::sync::Lazy;
|
||||
use surrealdb::env::{arch, os};
|
||||
|
||||
/// Stores the current release identifier
|
||||
pub static RELEASE: Lazy<String> =
|
||||
Lazy::new(|| format!("{} for {} on {}", *PKG_VERSION, os(), arch()));
|
||||
|
||||
pub async fn init() -> Result<(), Error> {
|
||||
// Log version
|
||||
info!("Running {}", release());
|
||||
info!("Running {}", *RELEASE);
|
||||
// All ok
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the current release identifier
|
||||
pub fn release() -> String {
|
||||
format!("{} for {} on {}", *PKG_VERSION, os(), arch())
|
||||
}
|
||||
|
|
|
@ -19,15 +19,35 @@ mod cli_integration {
|
|||
const TWO_SECS: time::Duration = time::Duration::new(2, 0);
|
||||
|
||||
#[test]
|
||||
fn version() {
|
||||
fn version_command() {
|
||||
assert!(common::run("version").output().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help() {
|
||||
fn version_flag_short() {
|
||||
assert!(common::run("-V").output().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_flag_long() {
|
||||
assert!(common::run("--version").output().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_command() {
|
||||
assert!(common::run("help").output().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_flag_short() {
|
||||
assert!(common::run("-h").output().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_flag_long() {
|
||||
assert!(common::run("--help").output().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nonexistent_subcommand() {
|
||||
assert!(common::run("nonexistent").output().is_err());
|
||||
|
|
Loading…
Reference in a new issue