VERSION file parsing

This commit is contained in:
Cadey Ratio 2020-05-31 13:05:32 -04:00
parent 730de12a63
commit ab775befb1
3 changed files with 18 additions and 0 deletions

View File

@ -6,6 +6,7 @@ use structopt::StructOpt;
mod changelog;
mod cmd;
mod gitea;
mod version;
#[derive(StructOpt, Debug)]
pub(crate) struct Common {

16
src/version.rs Normal file
View File

@ -0,0 +1,16 @@
use anyhow::Result;
use std::{fs, path::PathBuf};
fn read_version(fname: PathBuf) -> Result<String> {
let version = fs::read_to_string(fname)?;
Ok(version.trim().into())
}
#[cfg(test)]
mod tests {
#[test]
fn read_version() {
let version = super::read_version("./testdata/VERSION".into()).unwrap();
assert_eq!(version, "0.1.0");
}
}

1
testdata/VERSION vendored Normal file
View File

@ -0,0 +1 @@
0.1.0