Skip to content

Commit

Permalink
chore(cli): better version with build info (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Apr 28, 2023
1 parent 53d8863 commit 01834e6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ humantime-serde = "1.1.1"
indicatif = "0.17.3"
itertools = "0.10.5"
logos = "0.13.0"
once_cell = "1.17.1"
rustyline = "11.0.0"
serde = { version = "1.0.159", features = ["derive"] }
serde_json = "1.0.95"
Expand All @@ -39,6 +40,9 @@ tokio = { version = "1.26", features = [
toml = "0.7.3"
url = { version = "2.3.1", default-features = false }

[build-dependencies]
vergen = { version = "8.1.3", features = ["build", "git", "gitcl"] }

[[bin]]
name = "bendsql"
path = "src/main.rs"
Expand Down
21 changes: 21 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 Datafuse Labs.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::error::Error;
use vergen::EmitBuilder;

fn main() -> Result<(), Box<dyn Error>> {
EmitBuilder::builder().all_build().all_git().emit()?;
Ok(())
}
11 changes: 10 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ use std::{collections::BTreeMap, io::stdin};
use anyhow::{anyhow, Result};
use clap::{CommandFactory, Parser, ValueEnum};
use config::{Config, OutputFormat};
use once_cell::sync::Lazy;

static VERSION: Lazy<String> = Lazy::new(|| {
let version = option_env!("CARGO_PKG_VERSION").unwrap_or("unknown");
let sha = option_env!("VERGEN_GIT_DESCRIBE").unwrap_or("dev");
let timestamp = option_env!("VERGEN_BUILD_TIMESTAMP").unwrap_or("");
format!("{}-{}({})", version, sha, timestamp)
});

/// Supported file format and options:
/// https://databend.rs/doc/sql-reference/file-format-options
Expand Down Expand Up @@ -83,8 +91,9 @@ impl InputFormat {
}

#[derive(Debug, Parser, PartialEq)]
#[command(version = VERSION.as_str())]
// disable default help flag since it would conflict with --host
#[command(author, version, about, disable_help_flag = true)]
#[command(author, about, disable_help_flag = true)]
struct Args {
#[clap(long, help = "Print help information")]
help: bool,
Expand Down
3 changes: 2 additions & 1 deletion cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::config::OutputFormat;
use crate::config::Settings;
use crate::display::{format_write_progress, ChunkDisplay, FormatDisplay, ReplDisplay};
use crate::helper::CliHelper;
use crate::VERSION;

pub struct Session {
dsn: String,
Expand All @@ -49,7 +50,7 @@ impl Session {
let conn = new_connection(&dsn)?;
let info = conn.info();
if is_repl {
println!("Welcome to BendSQL.");
println!("Welcome to BendSQL {}.", VERSION.as_str());
println!(
"Trying connect to {}:{} as user {}.",
info.host, info.port, info.user
Expand Down

0 comments on commit 01834e6

Please sign in to comment.