Skip to content

Commit

Permalink
Ensure vromf_version errors surface, update wt_blk dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlareFlo committed Jan 24, 2024
1 parent 1a83252 commit e900fb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

21 changes: 12 additions & 9 deletions src/subcommands/vromf_version.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::fs;
use std::iter::{once};
use std::path::PathBuf;
use std::str::FromStr;
use clap::ArgMatches;
use serde_json::{json, Map, Value};
use wt_blk::vromf::VromfUnpacker;
use wt_version::Version;
use crate::error::CliError;

pub fn vromf_version(args: &ArgMatches) -> color_eyre::Result<()> {
Expand All @@ -14,22 +15,24 @@ pub fn vromf_version(args: &ArgMatches) -> color_eyre::Result<()> {

let versions: Vec<_> = if parsed_input_dir.is_file() {
let unpacker = VromfUnpacker::from_file((parsed_input_dir.clone(), fs::read(&parsed_input_dir)?))?;
vec![(parsed_input_dir.file_name().unwrap().to_string_lossy().to_string(), unpacker.latest_version().ok())]
vec![(parsed_input_dir.file_name().unwrap().to_string_lossy().to_string(), unpacker.latest_version()?)]
} else {
let dir = parsed_input_dir.read_dir()?;
let mut versions = vec![];
for file in dir {
let p = file?.path();
let unpacker = VromfUnpacker::from_file((p.clone(), fs::read(&p)?))?;
versions.push((p.file_name().unwrap().to_string_lossy().to_string(), unpacker.latest_version().ok()));
versions.push((p.file_name().unwrap().to_string_lossy().to_string(), unpacker.latest_version()?));
}
versions
}.into_iter().map(|(mut i,e)|{
i.push(' ');
i.push_str(&e.map(|e|e.to_string()).unwrap_or("0.0.0.0".to_owned()));
i
}).collect();
println!("{}", serde_json::to_string_pretty(&versions)?);
};
let json = Value::Array(
versions.into_iter()
.map(|e|{
Value::Object(Map::from_iter(once((e.0, json!(e.1.map(|e|e.to_string()))))))
}).collect()
);
println!("{}", serde_json::to_string_pretty(&json)?);

Ok(())
}

0 comments on commit e900fb7

Please sign in to comment.