Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): better version with build info #103

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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