From ba980ee2e7c49ad3a79735624a0531eec3d2eba3 Mon Sep 17 00:00:00 2001 From: Hunter Wittenborn Date: Sat, 23 Jul 2022 16:28:38 -0500 Subject: [PATCH] Release '0.5.0' --- CHANGELOG.md | 4 ++ Cargo.lock | 19 +++++++-- Cargo.toml | 3 +- completions/mpr.bash | 10 +++++ makedeb/PKGBUILD | 2 +- man/mpr.1.adoc | 4 ++ src/clone.rs | 2 +- src/color.rs | 8 ++++ src/main.rs | 7 ++++ src/message.rs | 16 +++----- src/search.rs | 53 +++++++----------------- src/update.rs | 96 ++++++++++++++++++++++++++++++++++++++++++++ 12 files changed, 168 insertions(+), 56 deletions(-) create mode 100644 src/color.rs create mode 100644 src/update.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a79350..e6defff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.5.0] - 2022-07-23 +### Added +- Added `update` command. + ## [0.4.2] - 2022-07-11 Internal changes used to test CI. No changes have been made for end users. diff --git a/Cargo.lock b/Cargo.lock index ebc92e3..e61f57a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -201,9 +201,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.8" +version = "3.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" +checksum = "54635806b078b7925d6e36810b1755f2a4b5b4d57560432c1ecf60bcbe10602b" dependencies = [ "atty", "bitflags", @@ -246,6 +246,16 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colored" +version = "2.0.0" +source = "git+https://github.com/mackwic/colored#11ffd20e7b5d1b48e4de7bb78ced26131ae5e114" +dependencies = [ + "atty", + "lazy_static", + "winapi 0.3.9", +] + [[package]] name = "console" version = "0.15.0" @@ -948,14 +958,15 @@ dependencies = [ name = "mpr" version = "0.4.2" dependencies = [ - "ansi_term", "bat", "chrono", - "clap 3.2.8", + "clap 3.2.14", + "colored", "dirs", "edit", "exitcode", "flate2", + "lazy_static", "quit", "regex", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index 40d3769..bfd75b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,14 @@ categories = ["command-line-utilities"] [dependencies] bat = "0.21.0" -ansi_term = "0.12.1" +colored = { git = "https://github.com/mackwic/colored" } chrono = "0.4.19" clap = { version = "3.2.8", features = ["cargo", "env"] } dirs = "4.0.0" edit = "0.1.4" exitcode = "1.1.2" flate2 = "1.0.24" +lazy_static = "1.4.0" quit = "1.1.4" regex = "1.6.0" reqwest = { version = "0.11.11", features = ["blocking", "json"] } diff --git a/completions/mpr.bash b/completions/mpr.bash index ee8e109..b71d3bb 100644 --- a/completions/mpr.bash +++ b/completions/mpr.bash @@ -26,6 +26,7 @@ _mpr() { 'info' 'list-comments' 'search' + 'update' 'whoami' ) local opts=( @@ -125,6 +126,15 @@ _mpr() { ;; esac ;; + update) + case "${prev}" in + --token|--mpr-url) + return + ;; + esac + + _mpr_gen_compreply '${opts[@]}' "${cur}" + ;; whoami) case "${prev}" in --token|--mpr-url) diff --git a/makedeb/PKGBUILD b/makedeb/PKGBUILD index 517ca9d..4e620ab 100644 --- a/makedeb/PKGBUILD +++ b/makedeb/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Hunter Wittenborn pkgname=mpr-cli -pkgver=0.4.2 +pkgver=0.5.0 pkgrel=1 pkgdesc='The official command-line interface for the makedeb Package Repository' arch=('any') diff --git a/man/mpr.1.adoc b/man/mpr.1.adoc index f9ab0dc..659dbbc 100644 --- a/man/mpr.1.adoc +++ b/man/mpr.1.adoc @@ -13,6 +13,7 @@ mpr - The official command-line interface for the makedeb Package Repository *mpr* info _pkgname_ [_options_] ... *mpr* list-comments _pkgbase_ [_options_] ... *mpr* search _query_ ... [_options_] ... +*mpr* update *mpr* whoami [_options_] ... == DESCRIPTION @@ -35,6 +36,9 @@ List comments of a package base on the MPR. *search*:: Search the package list on the MPR. +*update*:: +Updates the APT cache on the system. The MPR cache is not updated as part of this process, as it automatically gets updated when needed commands find it to be old. + *whoami*:: Show the currently authenticated user. diff --git a/src/clone.rs b/src/clone.rs index 1ba4673..8990da7 100644 --- a/src/clone.rs +++ b/src/clone.rs @@ -30,7 +30,7 @@ pub fn clone(args: &clap::ArgMatches) { ) ); - message::error_bold(&format!(" {} clone '{}'", clap::crate_name!(), pkgbase)); + message::error(&format!(" {} clone '{}'", clap::crate_name!(), pkgbase)); } None => (), diff --git a/src/color.rs b/src/color.rs new file mode 100644 index 0000000..41f3a5a --- /dev/null +++ b/src/color.rs @@ -0,0 +1,8 @@ +pub use colored::Colorize; +use colored::CustomColor; +use lazy_static::lazy_static; + +lazy_static! { + pub static ref UBUNTU_ORANGE: CustomColor = CustomColor::new(255, 175, 0); + pub static ref UBUNTU_PURPLE: CustomColor = CustomColor::new(95, 95, 255); +} diff --git a/src/main.rs b/src/main.rs index f4b5e01..22d9122 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,13 @@ mod cache; mod clone; +mod color; mod comment; mod info; mod list_comments; mod message; mod pkglist; mod search; +mod update; mod util; mod whoami; @@ -125,6 +127,10 @@ fn get_cli() -> Command<'static> { .long("mpr-only") ) ) + .subcommand( + Command::new("update") + .about("Update the APT cache on the system") + ) .subcommand( Command::new("whoami") .about("Show the currently authenticated user") @@ -142,6 +148,7 @@ fn main() { Some(("list-comments", args)) => list_comments::list_comments(args), Some(("pkglist", args)) => pkglist::pkglist(args), Some(("search", args)) => search::search(args), + Some(("update", args)) => update::update(args), Some(("whoami", args)) => whoami::whoami(args), _ => {} }; diff --git a/src/message.rs b/src/message.rs index c489796..db5d3ba 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,17 +1,13 @@ -use ansi_term::{Colour, Style}; +use crate::color::Colorize; pub fn info(str: &str) { - println!("{}", str); + println!("{} {}", "Info:".cyan().bold(), str); } -pub fn error(str: &str) { - println!("{} {}", Colour::Red.paint("Err:"), str); +pub fn warning(str: &str) { + println!("{} {}", "Err:".yellow().bold(), str); } -pub fn error_bold(str: &str) { - println!( - "{} {}", - Colour::Red.paint("Err:"), - Style::new().bold().paint(str) - ); +pub fn error(str: &str) { + println!("{} {}", "Err:".red().bold(), str); } diff --git a/src/search.rs b/src/search.rs index 9bb2836..27ccc94 100644 --- a/src/search.rs +++ b/src/search.rs @@ -1,8 +1,8 @@ use crate::{ cache::{Cache, CachePackage, CachePackageSource, MprCache}, + color::{self, Colorize}, message, }; -use ansi_term::{Colour, Style}; use chrono::{TimeZone, Utc}; use rust_apt::cache::Cache as AptCache; use std::{collections::HashMap, fmt::Write}; @@ -131,7 +131,12 @@ pub fn pkg_info(package_map: &HashMap<&String, Vec<&CachePackage>>, pkg_str: &St let mut sources_str = String::from("["); for source in sources { - write!(sources_str, "{}, ", Colour::Fixed(63).paint(source)).unwrap(); + write!( + sources_str, + "{}, ", + source.custom_color(*color::UBUNTU_PURPLE) + ) + .unwrap(); } // Remove the trailing ', ' at the end of the string. Then add the closing ']'. @@ -143,7 +148,7 @@ pub fn pkg_info(package_map: &HashMap<&String, Vec<&CachePackage>>, pkg_str: &St writeln!( result, "{}/{} {}", - Colour::Fixed(214).paint(pkg.pkgname.as_str()), + pkg.pkgname.as_str().custom_color(*color::UBUNTU_ORANGE), pkg.version, sources_str ) @@ -152,13 +157,7 @@ pub fn pkg_info(package_map: &HashMap<&String, Vec<&CachePackage>>, pkg_str: &St // pkgdesc. match &pkg.pkgdesc { Some(pkgdesc) => { - writeln!( - result, - "{} {}", - Style::new().bold().paint("Description:"), - pkgdesc - ) - .unwrap(); + writeln!(result, "{} {}", "Description:".bold(), pkgdesc).unwrap(); } None => (), @@ -167,13 +166,7 @@ pub fn pkg_info(package_map: &HashMap<&String, Vec<&CachePackage>>, pkg_str: &St // Maintainer. match &pkg.maintainer { Some(maintainer) => { - writeln!( - result, - "{} {}", - Style::new().bold().paint("Maintainer:"), - maintainer - ) - .unwrap(); + writeln!(result, "{} {}", "Maintainer:".bold(), maintainer).unwrap(); } None => (), @@ -181,26 +174,14 @@ pub fn pkg_info(package_map: &HashMap<&String, Vec<&CachePackage>>, pkg_str: &St // Votes. match &pkg.num_votes { - Some(num_votes) => writeln!( - result, - "{} {}", - Style::new().bold().paint("Votes:"), - num_votes - ) - .unwrap(), + Some(num_votes) => writeln!(result, "{} {}", "Votes:".bold(), num_votes).unwrap(), None => (), } // Popularity. match &pkg.popularity { - Some(popularity) => writeln!( - result, - "{} {}", - Style::new().bold().paint("Popularity:"), - popularity - ) - .unwrap(), + Some(popularity) => writeln!(result, "{} {}", "Popularity:".bold(), popularity).unwrap(), None => (), } @@ -210,17 +191,11 @@ pub fn pkg_info(package_map: &HashMap<&String, Vec<&CachePackage>>, pkg_str: &St match &pkg.ood { Some(ood) => { let dt = Utc.timestamp(*ood as i64, 0).format("%Y-%m-%d").to_string(); - writeln!( - result, - "{} {}", - Style::new().bold().paint("Out of Date:"), - dt - ) - .unwrap(); + writeln!(result, "{} {}", "Out of Date:".bold(), dt).unwrap(); } None => { - writeln!(result, "{} N/A", Style::new().bold().paint("Out of Date:")).unwrap(); + writeln!(result, "{} N/A", "Out of Date:".bold()).unwrap(); } } } diff --git a/src/update.rs b/src/update.rs new file mode 100644 index 0000000..f9fb4a6 --- /dev/null +++ b/src/update.rs @@ -0,0 +1,96 @@ +use crate::{color::Colorize, message}; +use rust_apt::{ + cache::{time_str, unit_str, Cache as AptCache, NumSys}, + progress::UpdateProgress, + raw::apt::Worker, +}; + +struct Update {} + +impl UpdateProgress for Update { + fn pulse_interval(&self) -> usize { + 500000 + } + + fn hit(&mut self, id: u32, description: String) { + println!( + "{}{} {}", + "Hit:".green().bold(), + id.to_string().green().bold(), + description + ); + } + + fn fetch(&mut self, id: u32, description: String, _file_size: u64) { + println!( + "{}{} {}", + "Get:".green().bold(), + id.to_string().green().bold(), + description + ); + } + + fn fail(&mut self, id: u32, description: String, status: u32, error_text: String) { + if status == 0 || status == 2 { + println!( + "{} {}", + format!("{}{} ({})", "Ign:", id, error_text).yellow().bold(), + description + ); + } else { + println!( + "{} {}", + format!("{}{} ({})", "Err:", id, error_text).yellow().bold(), + description + ); + } + } + + fn pulse( + &mut self, + _workers: Vec, + _percent: f32, + _total_bytes: u64, + _current_bytes: u64, + _current_cps: u64, + ) { + } + + fn done(&mut self) {} + + fn start(&mut self) {} + + fn stop( + &mut self, + fetched_bytes: u64, + elapsed_time: u64, + current_cps: u64, + _pending_errors: bool, + ) { + println!( + "{}", + format!( + "Fetched {} in {} ({}/s)", + unit_str(fetched_bytes, NumSys::Decimal), + time_str(elapsed_time), + unit_str(current_cps, NumSys::Decimal) + ) + .bold() + ) + } +} + +pub fn update(_args: &clap::ArgMatches) { + let cache = AptCache::new(); + let mut progress: Box = Box::new(Update {}); + + if let Err(error) = cache.update(&mut progress) { + for msg in error.what().split(';') { + if msg.starts_with("E:") { + message::error(msg.strip_prefix("E:").unwrap()); + } else if msg.starts_with("W:") { + message::warning(msg.strip_prefix("W:").unwrap()); + }; + } + }; +}