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

feat: Define custom raftify-cli --version command #161

Merged
merged 2 commits into from
Oct 13, 2024
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
24 changes: 23 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion raftify-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion raftify-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "raftify_cli"
version = "0.1.81"
version = "0.1.82"
edition = "2021"
description = "Raftify CLI tool"
license = "MIT/Apache-2.0"
build = "build.rs"

[dependencies]
log = { version = "0.4", features = ["std"] }
Expand All @@ -15,6 +16,7 @@ clap = { version = "4.5.18", features = ["derive"] }
raftify = { version = "=0.1.81", features = ["heed_storage", "inmemory_storage", "rocksdb_storage"] }
rocksdb = "0.19.0"
comfy-table = "7.1.1"
cfmt = { version = "0.1.0", package = "const_format" }

[lib]
name = "raftify_cli"
Expand All @@ -23,3 +25,4 @@ path = "src/mod.rs"
[build-dependencies]
tonic-build = "0.9.2"
built = "0.5"
toml = "0.8.19"
16 changes: 16 additions & 0 deletions raftify-cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
use std::fs;
use std::path::Path;
use toml::Value;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = Path::new("Cargo.toml");
let read = fs::read_to_string(path)
.expect("Failed to read Cargo.toml");
let toml: Value = read.parse::<Value>().expect("Failed to parse Cargo.toml");

if let Some(raftify_dep) = toml.get("dependencies").and_then(|deps| deps.get("raftify")) {
let version = raftify_dep.get("version").unwrap().as_str().unwrap();
let features = raftify_dep.get("features").unwrap().as_array().unwrap().iter().map(|f| f.as_str().unwrap()).collect::<Vec<_>>().join(", ");
println!("cargo:rustc-env=RAFTIFY_VERSION={}", &version[1..]);
println!("cargo:rustc-env=RAFTIFY_FEATURES={}", features);
}

built::write_built_file().expect("Failed to acquire build-time information");
Ok(())
}
12 changes: 10 additions & 2 deletions raftify-cli/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ use raftify::{
AbstractLogEntry, AbstractStateMachine, CustomFormatter, Result, StableStorage,
};

use cfmt::formatcp;

const RAFTIFY_VERSION: &str = env!("RAFTIFY_VERSION");
const RAFTIFY_FEATURES: &str = env!("RAFTIFY_FEATURES");
const VERSION_TEXT: &'static str = formatcp!("{PKG_VERSION}
(Built with raftify {}, Enabled features: {})", RAFTIFY_VERSION, RAFTIFY_FEATURES);

#[derive(Parser)]
#[command(name = "raftify")]
#[command(version = PKG_VERSION)]
#[command(name = PKG_NAME)]
#[command(author = PKG_AUTHORS)]
#[command(about = PKG_DESCRIPTION)]
#[command(version = VERSION_TEXT)]
#[command(long_version = VERSION_TEXT)]
struct App {
#[command(subcommand)]
command: Commands,
Expand Down
Loading