-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vromf_version subcommand and dependency to handle VROMF versions.
- Loading branch information
Showing
6 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use clap::{Arg, Command, ValueHint}; | ||
|
||
pub fn vromf_version() -> Command { | ||
Command::new("vromf_version") | ||
.long_flag("vromf_version") | ||
.arg(Arg::new("input") | ||
.short('i') | ||
.long("input_dir_or_file") | ||
.help("A single vromf file, or a folder of Vromf files. Does not recurse subdirs") | ||
.required(true) | ||
.value_hint(ValueHint::AnyPath)) | ||
.about("Prints version(s) from file or folder of vromfs") | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use std::str::FromStr; | ||
use clap::ArgMatches; | ||
use wt_blk::vromf::VromfUnpacker; | ||
use wt_version::Version; | ||
use crate::error::CliError; | ||
|
||
pub fn vromf_version(args: &ArgMatches) -> color_eyre::Result<()> { | ||
let input_dir = args | ||
.get_one::<String>("input") | ||
.ok_or(CliError::RequiredFlagMissing)?; | ||
let parsed_input_dir = PathBuf::from_str(&input_dir).or(Err(CliError::InvalidPath))?; | ||
|
||
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())] | ||
} 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 | ||
}.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)?); | ||
|
||
Ok(()) | ||
} |