Skip to content

Instantly share code, notes, and snippets.

@djhunter67
Created December 29, 2022 21:30
Show Gist options
  • Save djhunter67/a779d2ddd836eb4a4eb0027d36f96d23 to your computer and use it in GitHub Desktop.
Save djhunter67/a779d2ddd836eb4a4eb0027d36f96d23 to your computer and use it in GitHub Desktop.
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