Skip to content

Commit

Permalink
feat: Add flag to specify epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
Richterrettich committed Mar 12, 2020
1 parent 99b1aff commit 6208208
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2018"
build= "build.rs"

[dependencies]
rpm-rs = "0.2.1"
rpm-rs = "0.3.0"
clap= "2"
chrono = "0.4"
regex = "1"

[build-dependencies]
clap = "2"
clap = "2"
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub fn build_cli() -> App<'static, 'static> {
.help("Specify a version")
.default_value("1.0.0")
.takes_value(true))
.arg(Arg::with_name("epoch")
.long("epoch")
.value_name("EPOCH")
.help("Specify an epoch")
.default_value("0")
.takes_value(true))
.arg(Arg::with_name("license")
.long("license")
.value_name("LICENSE")
Expand Down
19 changes: 15 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ fn main() -> Result<(), AppError> {
let license = matches.value_of("license").unwrap();
let arch = matches.value_of("arch").unwrap();
let description = matches.value_of("desc").unwrap();
let epoch: i32 = matches
.value_of("epoch")
.unwrap()
.parse()
.map_err(|_e| AppError::new("unable to convert provided epoch value to integer"))?;

let release = matches.value_of("release").unwrap();

Expand All @@ -36,7 +41,9 @@ fn main() -> Result<(), AppError> {
builder = builder.with_file(src, options)?;
}

builder = builder.release(release.parse::<u16>().unwrap());
builder = builder
.release(release.parse::<u16>().unwrap())
.epoch(epoch);

let files = matches
.values_of("exec-file")
Expand Down Expand Up @@ -233,7 +240,11 @@ fn parse_dependency(re: &Regex, line: &str) -> Result<rpm::Dependency, AppError>
"invalid pattern in dependency block {}",
line
)))?;
let parts:Vec<String> = parts.iter().filter(|c| c.is_some()).map(|c| String::from(c.unwrap().as_str())).collect();
let parts: Vec<String> = parts
.iter()
.filter(|c| c.is_some())
.map(|c| String::from(c.unwrap().as_str()))
.collect();

if parts.len() <= 2 {
Ok(rpm::Dependency::any(&parts[1]))
Expand Down Expand Up @@ -283,12 +294,12 @@ impl std::fmt::Debug for AppError {

impl From<std::io::Error> for AppError {
fn from(err: std::io::Error) -> AppError {
AppError::new(format!("{}",err))
AppError::new(format!("{}", err))
}
}

impl From<rpm::RPMError> for AppError {
fn from(err: rpm::RPMError) -> AppError {
AppError::new(format!("{}",err))
AppError::new(format!("{}", err))
}
}
6 changes: 4 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::PathBuf;
use std::process::Command;

#[test]
fn test_gzipped() -> Result<(), Box<std::error::Error>> {
fn test_gzipped() -> Result<(), Box<dyn std::error::Error>> {
let mut tmp_dir = env::temp_dir();
tmp_dir.push("rpm-builder-test-gzipped");
fs::create_dir_all(&tmp_dir)?;
Expand Down Expand Up @@ -49,7 +49,7 @@ fn test_gzipped() -> Result<(), Box<std::error::Error>> {
}

#[test]
fn test_not_compressed() -> Result<(), Box<std::error::Error>> {
fn test_not_compressed() -> Result<(), Box<dyn std::error::Error>> {
let mut tmp_dir = env::temp_dir();
tmp_dir.push("rpm-builder-test-not-compressed");
fs::create_dir_all(&tmp_dir)?;
Expand All @@ -65,6 +65,8 @@ fn test_not_compressed() -> Result<(), Box<std::error::Error>> {
"target/debug/rpm-builder:/usr/bin/rpm-builder",
"--version",
"1.0.0",
"--epoch",
"5",
"rpm-builder",
"-o",
&out_file.to_string_lossy(),
Expand Down

0 comments on commit 6208208

Please sign in to comment.