Skip to content

Commit

Permalink
feat: Add table views
Browse files Browse the repository at this point in the history
list and info-all now display their information in a table. Additional
information compared is now also displayed, and output will be coloured.
  • Loading branch information
bbastin committed Aug 1, 2024
1 parent 987bce9 commit adbc0cf
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 34 deletions.
127 changes: 114 additions & 13 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[package]
name = "assetinfo"
version = "0.8.0"
version = "0.9.0"
authors = ["Benedikt Bastin"]
edition = "2021"
description = "assetinfo is a tool to watch for versions of assets and their end-of-life date."
Expand All @@ -27,8 +27,10 @@ serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.121"
sha256 = "1.5.0"
simple_logger = "5.0.0"
tabled = "0.15.0"
tar = "0.4.41"
tokio = { version = "1.39.2", features = ["full"] }
tokio-stream = "0.1.15"

[dev-dependencies]
tempfile = "3.10.1"
15 changes: 7 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use log::error;
use std::{error::Error, fs, path::PathBuf, process::exit};

mod config;
mod table_view;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
Expand Down Expand Up @@ -53,10 +54,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
Commands::List {} => {
let db = Database::load(config.database_folder())?;

println!("Supported programs:");
for program in db.supported_programs {
println!("{} ({}): ", program.info.title, program.info.id);
}
table_view::list_supported_programs(&db.supported_programs);
}
Commands::Info { name } => {
let db = Database::load(config.database_folder())?;
Expand All @@ -73,9 +71,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
Commands::InfoAll {} => {
let db = Database::load(config.database_folder())?;

for program in db.supported_programs {
let _ = gather_program_info(program).await;
}
// for program in db.supported_programs {
// let _ = gather_program_info(program).await;
// }
table_view::list_info_all(db.supported_programs).await?;
}
Commands::Update {} => {
update_database(&config).await?;
Expand All @@ -100,7 +99,7 @@ async fn gather_program_info(p: Program) -> Result<(), Box<dyn Error>> {
}

async fn print_info<T: Extractor>(e: T, p: &ProgramInfo) -> Result<(), Box<dyn Error>> {
for v in e.version().await? {
if let Some(v) = e.version().await? {
println!(
"{} ({}) found in Version {}",
p.title,
Expand Down
2 changes: 1 addition & 1 deletion src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{error::Error, path::PathBuf};

pub trait Extractor {
#[allow(async_fn_in_trait)]
async fn version(&self) -> Result<Vec<Version>, Box<dyn Error>>;
async fn version(&self) -> Result<Option<Version>, Box<dyn Error>>;

fn extractor_name() -> &'static str;
}
Expand Down
10 changes: 5 additions & 5 deletions src/sources/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::program::{BinaryExtractor, Extractor, Version};
use super::regex::parse_version;

impl Extractor for BinaryExtractor {
async fn version(&self) -> Result<Vec<Version>, Box<dyn Error>> {
async fn version(&self) -> Result<Option<Version>, Box<dyn Error>> {
if !self.path.exists() {
return Ok(Vec::default());
return Ok(None);
}

let r = if self.user.is_some() {
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Extractor for BinaryExtractor {
let r = parse_version(s.unwrap(), &self.regex);

match r {
Ok(version) => Ok(vec![version]),
Ok(version) => Ok(Some(version)),
Err(e) => {
error!("{e}");
Err(e)
Expand Down Expand Up @@ -155,9 +155,9 @@ mod tests {
assert!(res.is_ok());

let version = res.unwrap();
assert_eq!(version.len(), 1);
assert!(version.is_some());

let version = &version[0];
let version = version.unwrap();
assert_eq!(version.string, "1.2.3");

fs::remove_file(file_path).expect("Could not delete tmpfile");
Expand Down
Loading

0 comments on commit adbc0cf

Please sign in to comment.