Created
December 29, 2022 21:30
-
-
Save djhunter67/a779d2ddd836eb4a4eb0027d36f96d23 to your computer and use it in GitHub Desktop.
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
use regex::Regex; | |
use std::fs; | |
fn main() { | |
println!("Version: {}", version_getter()); | |
} | |
fn version_getter<'a>() -> String { | |
let path: String = String::from("../CHANGELOG.md"); | |
// Read the file contents | |
let contents: String = fs::read_to_string(path).unwrap(); | |
let mut version: String = String::from(""); | |
let re = Regex::new(r"^?(\d+)\.(\d+)\.(\d)").unwrap(); | |
// return on the line with brackets | |
for (_, word) in contents.lines().enumerate() { | |
if word.contains("] - 20") { | |
version = re.find(word).unwrap().as_str().to_string(); | |
break; | |
} | |
} | |
version | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment