-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Define custom
raftify-cli
--version command (#161)
* add long_version opt * feat: Print also raftify features --------- Co-authored-by: Gyubong <[email protected]>
- Loading branch information
1 parent
9396e11
commit 55bd392
Showing
5 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters