Skip to content

Commit

Permalink
feat: Define custom raftify-cli --version command (#161)
Browse files Browse the repository at this point in the history
* add long_version opt

* feat: Print also raftify features

---------

Co-authored-by: Gyubong <[email protected]>
  • Loading branch information
CHOUMnote and jopemachine authored Oct 13, 2024
1 parent 9396e11 commit 55bd392
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
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 @@ -14,6 +15,7 @@ built = "0.5"
clap = { version = "4.5.18", features = ["derive"] }
raftify = { version = "=0.1.81", features = ["heed_storage", "inmemory_storage", "rocksdb_storage"] }
comfy-table = "7.1.1"
cfmt = { version = "0.1.0", package = "const_format" }

[lib]
name = "raftify_cli"
Expand All @@ -22,3 +24,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

0 comments on commit 55bd392

Please sign in to comment.