Add fl_* variants for trace, debug, info, warn, error

The fl variants allow for passing a message id for the translation
instead of having to invoke the fl macro inside the formatter
i18n
trivernis 2 years ago committed by Julius Riegel
parent c858313fa3
commit 0a0268c19a

@ -12,6 +12,16 @@ macro_rules! prompt {
} }
} }
#[macro_export]
macro_rules! fl_prompt {
(default $def:tt, $message_id:literal) => {
prompt!(default $def, "{}", fl!($message_id))
};
(default $def:tt, $message_id:literal, $($arg:tt)*) => {
prompt!(default $def, "{}", fl!($message_id, $($arg)*))
};
}
#[macro_export] #[macro_export]
/// Macro for prompting the user with a multi select /// Macro for prompting the user with a multi select
macro_rules! multi_select { macro_rules! multi_select {

@ -3,7 +3,7 @@ use crossterm::style::Stylize;
use crate::builder::pacdiff::PacdiffBuilder; use crate::builder::pacdiff::PacdiffBuilder;
use crate::internal::config::Config; use crate::internal::config::Config;
use crate::logging::get_logger; use crate::logging::get_logger;
use crate::{fl, prompt}; use crate::{fl, fl_prompt, fl_warn, prompt};
use super::prompt_sudo_single; use super::prompt_sudo_single;
@ -40,13 +40,13 @@ pub async fn detect() {
"sudo pacdiff".reset().magenta() "sudo pacdiff".reset().magenta()
); );
let choice = prompt!(default no, "{}", fl!("run-pacdiff-now")); let choice = fl_prompt!(default no, "run-pacdiff-now");
if choice { if choice {
let config = Config::get(); let config = Config::get();
if config.base.pacdiff_warn { if config.base.pacdiff_warn {
tracing::warn!("{}", fl!("pacdiff-warning")); fl_warn!("pacdiff-warning");
if prompt!(default no, "{}", fl!("continue")) { if fl_prompt!(default no, "continue") {
PacdiffBuilder::pacdiff().await.unwrap(); PacdiffBuilder::pacdiff().await.unwrap();
} }
} else { } else {

@ -3,7 +3,7 @@ use std::fmt::{Debug, Display, Formatter};
use std::io; use std::io;
use crate::internal::exit_code::AppExitCode; use crate::internal::exit_code::AppExitCode;
use crate::{crash, fl}; use crate::{fl, fl_crash};
pub type AppResult<T> = Result<T, AppError>; pub type AppResult<T> = Result<T, AppError>;
@ -99,7 +99,7 @@ impl<T> SilentUnwrap<T> for AppResult<T> {
Ok(val) => val, Ok(val) => val,
Err(e) => { Err(e) => {
tracing::debug!("{e}"); tracing::debug!("{e}");
crash!(exit_code, "{}", fl!("error-occurred")) fl_crash!(exit_code, "error-occurred")
} }
} }
} }

@ -1,49 +0,0 @@
use std::{
collections::VecDeque,
path::{Path, PathBuf},
};
use futures::future;
use tokio::fs;
#[tracing::instrument(level = "trace")]
pub async fn rmdir_recursive(path: &Path) -> std::io::Result<()> {
let mut files: Vec<PathBuf> = Vec::new();
let mut folders: Vec<PathBuf> = Vec::new();
if path.is_dir() {
folders.push(path.into());
} else {
files.push(path.into());
}
let mut folders_to_scan: VecDeque<_> = folders.clone().into();
while let Some(path) = folders_to_scan.pop_front() {
let mut dir_content = fs::read_dir(&path).await?;
while let Some(entry) = dir_content.next_entry().await? {
let entry = entry.path();
if entry.is_dir() {
folders_to_scan.push_back(entry.clone());
folders.push(entry);
} else {
files.push(entry);
}
}
}
tracing::debug!("Deleting {} files", files.len());
future::try_join_all(files.into_iter().map(fs::remove_file)).await?;
tracing::debug!("Deleting {} folders", folders.len());
folders.reverse();
for folder in folders {
tracing::trace!("Deleting {folder:?}");
fs::remove_dir(folder).await?;
}
Ok(())
}

@ -30,3 +30,58 @@ macro_rules! fl {
i18n_embed_fl::fl!($crate::internal::i18n::LANG_LOADER, $message_id, $($args), *) i18n_embed_fl::fl!($crate::internal::i18n::LANG_LOADER, $message_id, $($args), *)
}}; }};
} }
#[macro_export]
macro_rules! fl_debug {
($message_id:literal) => {
tracing::debug!("{}", $crate::fl!($message_id))
};
($message_id:literal, $($arg:tt)*) => {
tracing::debug!("{}", $crate::fl!($message_id, $($args)*))
};
}
#[macro_export]
macro_rules! fl_trace {
($message_id:literal) => {
tracing::trace!("{}", $crate::fl!($message_id))
};
($message_id:literal, $($arg:tt)*) => {
tracing::trace!("{}", $crate::fl!($message_id, $($args)*))
};
}
#[macro_export]
macro_rules! fl_info {
($message_id:literal) => {
tracing::info!("{}", $crate::fl!($message_id))
};
($message_id:literal, $($arg:tt)*) => {
tracing::info!("{}", $crate::fl!($message_id, $($arg)*))
};
}
#[macro_export]
macro_rules! fl_warn {
($message_id:literal) => {
tracing::warn!("{}", $crate::fl!($message_id))
};
($message_id:literal, $($arg:tt)*) => {
tracing::warn!("{}", $crate::fl!($message_id, $($arg)*))
};
}
#[macro_export]
macro_rules! fl_error {
($message_id:literal) => {
tracing::error!("{}", $crate::fl!($message_id))
};
($message_id:literal, $($arg:tt)*) => {
tracing::error!("{}", $crate::fl!($message_id, $($args)*))
};
}

@ -11,7 +11,6 @@ pub mod dependencies;
mod detect; mod detect;
pub mod error; pub mod error;
pub mod exit_code; pub mod exit_code;
pub mod fs_utils;
pub mod rpc; pub mod rpc;
mod sort; mod sort;
pub mod structs; pub mod structs;

@ -18,6 +18,18 @@ macro_rules! crash {
} }
} }
#[macro_export]
/// Macro for printing a message and destructively exiting
macro_rules! fl_crash {
($exit_code:expr, $message_id:literal) => {
$crate::internal::utils::log_and_crash($crate::fl!($message_id), $exit_code)
};
($exit_code:expr, $message_id:literal, $($arg:tt)*) => {
$crate::internal::utils::log_and_crash($crate::fl!($message_id, $($arg)*), $exit_code)
};
}
#[macro_export] #[macro_export]
/// Cancelles the process /// Cancelles the process
macro_rules! cancelled { macro_rules! cancelled {

@ -31,7 +31,7 @@ use logging::init_logger;
async fn main() { async fn main() {
color_eyre::install().unwrap(); color_eyre::install().unwrap();
if unsafe { libc::geteuid() } == 0 { if unsafe { libc::geteuid() } == 0 {
crash!(AppExitCode::RunAsRoot, "{}", fl!("run-as-root")); fl_crash!(AppExitCode::RunAsRoot, "run-as-root");
} }
let args: Args = Args::parse(); let args: Args = Args::parse();
@ -64,11 +64,11 @@ async fn main() {
} }
Operation::Query(query_args) => cmd_query(query_args).await, Operation::Query(query_args) => cmd_query(query_args).await,
Operation::Upgrade(upgrade_args) => { Operation::Upgrade(upgrade_args) => {
tracing::info!("{}", fl!("system-upgrade")); fl_info!("system-upgrade");
operations::upgrade(upgrade_args, options).await; operations::upgrade(upgrade_args, options).await;
} }
Operation::Clean => { Operation::Clean => {
tracing::info!("{}", fl!("removing-orphans")); fl_info!("removing-orphans");
operations::clean(options).await; operations::clean(options).await;
} }
Operation::GenComp(gen_args) => cmd_gencomp(&gen_args), Operation::GenComp(gen_args) => cmd_gencomp(&gen_args),
@ -100,10 +100,10 @@ async fn cmd_install(args: InstallArgs, options: Options) {
if both { if both {
let sorted = sort(packages, options).await; let sorted = sort(packages, options).await;
if !sorted.nf.is_empty() { if !sorted.nf.is_empty() {
crash!( fl_crash!(
AppExitCode::PacmanError, AppExitCode::PacmanError,
"{}", "couldnt-find-packages",
fl!("couldnt-find-packages", packages = sorted.nf.join(", ")) packages = sorted.nf.join(", ")
); );
} }
if !sorted.repo.is_empty() { if !sorted.repo.is_empty() {
@ -111,13 +111,14 @@ async fn cmd_install(args: InstallArgs, options: Options) {
} }
if !sorted.aur.is_empty() { if !sorted.aur.is_empty() {
if Config::read().base.aur_verification_prompt { if Config::read().base.aur_verification_prompt {
tracing::info!("{}", fl!("following-packages")); fl_info!("following-packages");
get_logger().print_list(&sorted.aur, " ", 2); get_logger().print_list(&sorted.aur, " ", 2);
newline!(); newline!();
tracing::warn!("{}", fl!("aur-warning")); fl_warn!("aur-warning");
let cont = noconfirm || prompt!(default no, "{}", fl!("are-you-sure")); let cont = noconfirm || fl_prompt!(default no, "are-you-sure");
if !cont { if !cont {
tracing::info!("{}", fl!("exiting")); fl_info!("exiting");
std::process::exit(AppExitCode::PacmanError as i32); std::process::exit(AppExitCode::PacmanError as i32);
} }
} }
@ -131,10 +132,7 @@ async fn cmd_install(args: InstallArgs, options: Options) {
#[tracing::instrument(level = "trace")] #[tracing::instrument(level = "trace")]
async fn cmd_remove(args: RemoveArgs, options: Options) { async fn cmd_remove(args: RemoveArgs, options: Options) {
let packages = args.packages; let packages = args.packages;
tracing::info!( fl_info!("uninstalling-packages", packages = packages.join(", "));
"{}",
fl!("uninstalling-packages", packages = packages.join(", "))
);
operations::uninstall(packages, options).await; operations::uninstall(packages, options).await;
} }
@ -146,20 +144,20 @@ async fn cmd_search(args: InstallArgs, options: Options) {
let mut results = Vec::new(); let mut results = Vec::new();
if args.repo || both { if args.repo || both {
tracing::info!("{}", fl!("searching-repos", query = query_string.clone())); fl_info!("searching-repos", query = query_string.clone());
let res = operations::search(&query_string, options).await; let res = operations::search(&query_string, options).await;
results.extend(res); results.extend(res);
} }
if args.aur || both { if args.aur || both {
tracing::info!("{}", fl!("searching-aur", query = query_string.clone())); fl_info!("searching-aur", query = query_string.clone());
let res = operations::aur_search(&query_string, args.by, options).await; let res = operations::aur_search(&query_string, args.by, options).await;
results.extend(res); results.extend(res);
} }
if results.is_empty() { if results.is_empty() {
tracing::info!("{}", fl!("no-results")); fl_info!("no-results");
} else { } else {
tracing::info!("{}", fl!("results")); fl_info!("results");
results.sort_by(|a, b| { results.sort_by(|a, b| {
let a_score = a.score(&query_string); let a_score = a.score(&query_string);
@ -184,7 +182,7 @@ async fn cmd_query(args: QueryArgs) {
let both = !args.aur && !args.repo && args.info.is_none(); let both = !args.aur && !args.repo && args.info.is_none();
if args.repo { if args.repo {
tracing::info!("{}", fl!("installed-repo-packages")); fl_info!("installed-repo-packages");
PacmanQueryBuilder::native() PacmanQueryBuilder::native()
.color(PacmanColor::Always) .color(PacmanColor::Always)
.query() .query()
@ -193,7 +191,7 @@ async fn cmd_query(args: QueryArgs) {
} }
if args.aur { if args.aur {
tracing::info!("{}", fl!("installed-aur-packages")); fl_info!("installed-aur-packages");
PacmanQueryBuilder::foreign() PacmanQueryBuilder::foreign()
.color(PacmanColor::Always) .color(PacmanColor::Always)
.query() .query()
@ -202,7 +200,7 @@ async fn cmd_query(args: QueryArgs) {
} }
if both { if both {
tracing::info!("{}", fl!("installed-packages")); fl_info!("installed-packages");
PacmanQueryBuilder::all() PacmanQueryBuilder::all()
.color(PacmanColor::Always) .color(PacmanColor::Always)
.query() .query()
@ -230,11 +228,11 @@ fn cmd_gencomp(args: &GenCompArgs) {
); );
} else { } else {
let shell: Shell = Shell::from_str(&args.shell).unwrap_or_else(|e| { let shell: Shell = Shell::from_str(&args.shell).unwrap_or_else(|e| {
crash!(AppExitCode::Other, "{}", fl!("invalid-shell", shell = e)); fl_crash!(AppExitCode::Other, "invalid-shell", shell = e);
}); });
if shell == Shell::Zsh { if shell == Shell::Zsh {
crash!(AppExitCode::Other, "{}", fl!("zsh-error")); fl_crash!(AppExitCode::Other, "zsh-error");
}; };
clap_complete::generate( clap_complete::generate(

@ -3,7 +3,7 @@ use futures::future;
use crate::{ use crate::{
builder::{makepkg::MakePkgBuilder, pacman::PacmanInstallBuilder}, builder::{makepkg::MakePkgBuilder, pacman::PacmanInstallBuilder},
fl, fl, fl_info,
internal::{dependencies::DependencyInformation, error::AppResult}, internal::{dependencies::DependencyInformation, error::AppResult},
multi_progress, normal_output, multi_progress, normal_output,
operations::{ operations::{
@ -30,15 +30,12 @@ impl AurDependencyInstallation {
.collect(); .collect();
if !aur_dependencies.is_empty() { if !aur_dependencies.is_empty() {
tracing::info!( fl_info!(
"{}", "installing-from-aur",
fl!( amountOfPkgs = format!(
"installing-from-aur", "{} {}",
amountOfPkgs = format!( aur_dependencies.len(),
"{} {}", fl!("packages", pkgNum = aur_dependencies.len())
aur_dependencies.len(),
fl!("packages", pkgNum = aur_dependencies.len())
)
) )
); );
let batches = create_dependency_batches(aur_dependencies); let batches = create_dependency_batches(aur_dependencies);

@ -3,7 +3,7 @@ use aur_rpc::PackageInfo;
use futures::future; use futures::future;
use crate::{ use crate::{
fl, fl_info,
internal::{dependencies::DependencyInformation, error::AppResult, structs::Options}, internal::{dependencies::DependencyInformation, error::AppResult, structs::Options},
multi_progress, normal_output, multi_progress, normal_output,
operations::BuildContext, operations::BuildContext,
@ -33,7 +33,7 @@ impl AurDownload {
.await?; .await?;
normal_output!(); normal_output!();
tracing::info!("{}", fl!("all-sources-ready")); fl_info!("all-sources-ready");
Ok(AurReview { Ok(AurReview {
options: self.options, options: self.options,

@ -2,7 +2,7 @@ use crossterm::style::Stylize;
use futures::future; use futures::future;
use crate::{ use crate::{
fl, fl, fl_prompt,
internal::{ internal::{
dependencies::DependencyInformation, dependencies::DependencyInformation,
error::{AppError, AppResult}, error::{AppError, AppResult},
@ -43,7 +43,7 @@ impl AurFetch {
if print_aur_package_list(&package_infos.iter().collect::<Vec<_>>()).await if print_aur_package_list(&package_infos.iter().collect::<Vec<_>>()).await
&& !self.options.noconfirm && !self.options.noconfirm
&& !self.options.upgrade && !self.options.upgrade
&& !prompt!(default yes, "{}", fl!("some-pkgs-already-installed")) && !fl_prompt!(default yes, "some-pkgs-already-installed")
{ {
return Err(AppError::UserCancellation); return Err(AppError::UserCancellation);
} }
@ -62,7 +62,7 @@ impl AurFetch {
print_dependency_list(&dependencies).await; print_dependency_list(&dependencies).await;
if !self.options.noconfirm && !prompt!(default yes, "{}", fl!("do-you-want-to-install")) { if !self.options.noconfirm && !fl_prompt!(default yes, "do-you-want-to-install") {
Err(AppError::UserCancellation) Err(AppError::UserCancellation)
} else { } else {
Ok(AurDownload { Ok(AurDownload {

@ -2,7 +2,7 @@ use tokio::fs;
use crate::{ use crate::{
builder::pager::PagerBuilder, builder::pager::PagerBuilder,
fl, fl, fl_info, fl_prompt,
internal::{ internal::{
dependencies::DependencyInformation, dependencies::DependencyInformation,
error::{AppError, AppResult}, error::{AppError, AppResult},
@ -26,7 +26,7 @@ impl AurReview {
pub async fn review_pkgbuild(self) -> AppResult<RepoDependencyInstallation> { pub async fn review_pkgbuild(self) -> AppResult<RepoDependencyInstallation> {
if !self.options.noconfirm { if !self.options.noconfirm {
if self.packages.len() == 1 { if self.packages.len() == 1 {
if prompt!(default yes, "{}", fl!("review", pkg = self.packages[0].clone())) { if fl_prompt!(default yes, "review", pkg = self.packages[0].clone()) {
self.review_single_package(&self.packages[0]).await?; self.review_single_package(&self.packages[0]).await?;
} }
} else { } else {
@ -36,7 +36,7 @@ impl AurReview {
self.review_single_package(pkg).await?; self.review_single_package(pkg).await?;
} }
} }
if !prompt!(default yes, "{}", fl!("do-you-still-want-to-install")) { if !fl_prompt!(default yes, "do-you-still-want-to-install") {
return Err(AppError::UserCancellation); return Err(AppError::UserCancellation);
} }
} }
@ -76,7 +76,7 @@ impl AurReview {
} }
} }
tracing::info!("{}", fl!("done-reviewing-pkg", pkg = pkg)); fl_info!("done-reviewing-pkg", pkg = pkg);
Ok(()) Ok(())
} }

@ -22,7 +22,7 @@ use crate::{
pacman::PacmanInstallBuilder, pacman::PacmanInstallBuilder,
pager::PagerBuilder, pager::PagerBuilder,
}, },
crash, fl, crash, fl, fl_info,
internal::{ internal::{
alpm::{Alpm, PackageFrom}, alpm::{Alpm, PackageFrom},
error::{AppError, AppResult}, error::{AppError, AppResult},
@ -161,8 +161,9 @@ pub async fn build_and_install(
make_opts: MakePkgBuilder, make_opts: MakePkgBuilder,
install_opts: PacmanInstallBuilder, install_opts: PacmanInstallBuilder,
) -> AppResult<()> { ) -> AppResult<()> {
tracing::info!("{}", fl!("building-packages")); fl_info!("building-packages");
multi_progress!(); multi_progress!();
let results = future::join_all( let results = future::join_all(
ctxs.into_iter() ctxs.into_iter()
.map(|ctx| build_package(ctx, make_opts.clone())), .map(|ctx| build_package(ctx, make_opts.clone())),
@ -183,7 +184,7 @@ pub async fn build_and_install(
ctxs.len(), ctxs.len(),
fl!("packages", pkgNum = ctxs.len()) fl!("packages", pkgNum = ctxs.len())
); );
tracing::info!("{}", fl!("installing-packages")); fl_info!("installing-packages");
install_packages(ctxs, install_opts).await?; install_packages(ctxs, install_opts).await?;

@ -1,6 +1,6 @@
use crate::{ use crate::{
builder::pacman::PacmanUninstallBuilder, builder::pacman::PacmanUninstallBuilder,
fl, fl, fl_info, fl_prompt,
internal::{dependencies::DependencyInformation, error::AppResult, structs::Options}, internal::{dependencies::DependencyInformation, error::AppResult, structs::Options},
prompt, prompt,
}; };
@ -20,7 +20,7 @@ impl MakeDependencyRemoval {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if !make_depends.is_empty() if !make_depends.is_empty()
&& !self.options.noconfirm && !self.options.noconfirm
&& prompt!(default yes, "{}", fl!("remove-installed-make-deps")) && fl_prompt!(default yes, "remove-installed-make-deps")
{ {
PacmanUninstallBuilder::default() PacmanUninstallBuilder::default()
.packages(make_depends) .packages(make_depends)
@ -29,7 +29,7 @@ impl MakeDependencyRemoval {
.await?; .await?;
} }
tracing::info!("{}", fl!("done")); fl_info!("done");
Ok(()) Ok(())
} }

@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use crate::internal::error::{AppError, AppResult}; use crate::internal::error::{AppError, AppResult};
use crate::internal::exit_code::AppExitCode; use crate::internal::exit_code::AppExitCode;
use crate::{cancelled, crash, fl, Options}; use crate::{cancelled, crash, fl, fl_crash, Options};
use self::aur_fetch::AurFetch; use self::aur_fetch::AurFetch;
@ -99,7 +99,7 @@ pub async fn aur_install(packages: Vec<String>, options: Options) {
crash!(AppExitCode::RpcError, "{} {e}", fl!("aur-rpc-crash")) crash!(AppExitCode::RpcError, "{} {e}", fl!("aur-rpc-crash"))
} }
AppError::BuildStepViolation => { AppError::BuildStepViolation => {
crash!(AppExitCode::MakePkgError, "{}", fl!("failed-to-build")) fl_crash!(AppExitCode::MakePkgError, "failed-to-build")
} }
AppError::BuildError { pkg_name } => { AppError::BuildError { pkg_name } => {
crash!( crash!(
@ -122,7 +122,7 @@ pub async fn aur_install(packages: Vec<String>, options: Options) {
AppError::MakePkg(msg) => { AppError::MakePkg(msg) => {
crash!(AppExitCode::MakePkgError, "{} {msg}", fl!("makepkg-failed")) crash!(AppExitCode::MakePkgError, "{} {msg}", fl!("makepkg-failed"))
} }
_ => crash!(AppExitCode::Other, "{}", fl!("unknown-error")), _ => fl_crash!(AppExitCode::Other, "unknown-error"),
} }
} }
} }

@ -2,7 +2,7 @@ use std::collections::HashSet;
use crate::{ use crate::{
builder::pacman::PacmanInstallBuilder, builder::pacman::PacmanInstallBuilder,
fl, fl_info,
internal::{dependencies::DependencyInformation, error::AppResult, structs::Options}, internal::{dependencies::DependencyInformation, error::AppResult, structs::Options},
}; };
@ -24,7 +24,7 @@ impl RepoDependencyInstallation {
.collect(); .collect();
if !repo_dependencies.is_empty() { if !repo_dependencies.is_empty() {
tracing::info!("{}", fl!("installing-repo-deps")); fl_info!("installing-repo-deps");
PacmanInstallBuilder::default() PacmanInstallBuilder::default()
.as_deps(true) .as_deps(true)
.packages(repo_dependencies) .packages(repo_dependencies)

@ -2,9 +2,11 @@ use crate::builder::paccache::PaccacheBuilder;
use crate::builder::pacman::PacmanQueryBuilder; use crate::builder::pacman::PacmanQueryBuilder;
use crate::builder::pacman::PacmanUninstallBuilder; use crate::builder::pacman::PacmanUninstallBuilder;
use crate::builder::rm::RmBuilder; use crate::builder::rm::RmBuilder;
use crate::crash;
use crate::fl; use crate::fl;
use crate::fl_crash;
use crate::fl_info;
use crate::fl_prompt;
use crate::internal::exit_code::AppExitCode; use crate::internal::exit_code::AppExitCode;
use crate::internal::utils::get_cache_dir; use crate::internal::utils::get_cache_dir;
@ -25,20 +27,17 @@ pub async fn clean(options: Options) {
if orphaned_packages.stdout.as_str().is_empty() { if orphaned_packages.stdout.as_str().is_empty() {
// If no orphaned packages found, do nothing // If no orphaned packages found, do nothing
tracing::info!("{}", fl!("no-orphans")); fl_info!("no-orphans");
} else { } else {
// Prompt users whether to remove orphaned packages // Prompt users whether to remove orphaned packages
tracing::info!( fl_info!(
"{}", "removing-orphans-would",
fl!( packages = orphaned_packages.stdout.trim_end()
"removing-orphans-would",
packages = orphaned_packages.stdout.trim_end()
)
); );
let cont = noconfirm || prompt!(default no, "Continue?"); let cont = noconfirm || prompt!(default no, "Continue?");
if !cont { if !cont {
// If user doesn't want to continue, break // If user doesn't want to continue, break
tracing::info!("{}", fl!("exiting")); fl_info!("exiting");
std::process::exit(AppExitCode::PacmanError as i32); std::process::exit(AppExitCode::PacmanError as i32);
} }
@ -61,14 +60,14 @@ pub async fn clean(options: Options) {
.await; .await;
if result.is_err() { if result.is_err() {
crash!(AppExitCode::PacmanError, "{}", fl!("failed-remove-orphans")); fl_crash!(AppExitCode::PacmanError, "failed-remove-orphans");
} else { } else {
tracing::info!("{}", fl!("success-remove-orphans")); fl_info!("success-remove-orphans");
} }
} }
// Prompt the user whether to clear the Amethyst cache // Prompt the user whether to clear the Amethyst cache
let clear_ame_cache = noconfirm || prompt!(default no, "{}", fl!("clear-pkgbuild-cache")); let clear_ame_cache = noconfirm || fl_prompt!(default no, "clear-pkgbuild-cache");
if clear_ame_cache { if clear_ame_cache {
let cache_dir = get_cache_dir(); let cache_dir = get_cache_dir();
@ -82,7 +81,7 @@ pub async fn clean(options: Options) {
} }
// Prompt the user whether to clear cache or not // Prompt the user whether to clear cache or not
let clear_pacman_cache = noconfirm || prompt!(default no, "{}", fl!("clear-pacman-cache")); let clear_pacman_cache = noconfirm || fl_prompt!(default no, "clear-pacman-cache");
if clear_pacman_cache { if clear_pacman_cache {
// Clear pacman's cache // Clear pacman's cache
@ -96,13 +95,13 @@ pub async fn clean(options: Options) {
.await; .await;
if let Err(e) = result { if let Err(e) = result {
crash!( fl_crash!(
AppExitCode::PacmanError, AppExitCode::PacmanError,
"{}", "failed-clear-cache",
fl!("failed-clear-cache", error = e.to_string()) error = e.to_string()
) );
} else { } else {
tracing::info!("{}", fl!("success-clear-cache")); fl_info!("success-clear-cache");
} }
} }
} }

@ -1,15 +1,12 @@
use crate::builder::pacman::PacmanInstallBuilder; use crate::builder::pacman::PacmanInstallBuilder;
use crate::internal::exit_code::AppExitCode; use crate::internal::exit_code::AppExitCode;
use crate::{crash, fl, Options}; use crate::{fl_crash, fl_info, Options};
#[tracing::instrument(level = "trace")] #[tracing::instrument(level = "trace")]
pub async fn install(packages: Vec<String>, options: Options) { pub async fn install(packages: Vec<String>, options: Options) {
tracing::info!( fl_info!(
"{}", "installing-packages-from-repos",
fl!( packages = packages.join(", ")
"installing-packages-from-repos",
packages = packages.join(", ")
)
); );
if !packages.is_empty() { if !packages.is_empty() {
@ -21,10 +18,10 @@ pub async fn install(packages: Vec<String>, options: Options) {
.await; .await;
if result.is_err() { if result.is_err() {
crash!( fl_crash!(
AppExitCode::PacmanError, AppExitCode::PacmanError,
"{}", "error-install",
fl!("error-install", error = packages.join(", ")) error = packages.join(", ")
); );
} }

@ -4,7 +4,7 @@ use tokio::fs;
use crate::builder::pacman::PacmanUninstallBuilder; use crate::builder::pacman::PacmanUninstallBuilder;
use crate::internal::exit_code::AppExitCode; use crate::internal::exit_code::AppExitCode;
use crate::{crash, fl, Options}; use crate::{fl_crash, Options};
/// Uninstalls the given packages /// Uninstalls the given packages
#[tracing::instrument(level = "trace")] #[tracing::instrument(level = "trace")]
@ -18,7 +18,7 @@ pub async fn uninstall(packages: Vec<String>, options: Options) {
.uninstall() .uninstall()
.await .await
.unwrap_or_else(|_| { .unwrap_or_else(|_| {
crash!(AppExitCode::PacmanError, "{}", fl!("failed-remove-pkgs")); fl_crash!(AppExitCode::PacmanError, "failed-remove-pkgs");
}); });
for package in packages { for package in packages {

@ -5,7 +5,7 @@ use crate::internal::error::SilentUnwrap;
use crate::internal::exit_code::AppExitCode; use crate::internal::exit_code::AppExitCode;
use crate::internal::rpc::rpcinfo; use crate::internal::rpc::rpcinfo;
use crate::operations::aur_install::aur_install; use crate::operations::aur_install::aur_install;
use crate::{fl, Options}; use crate::{fl_error, fl_info, fl_warn, Options};
/// Upgrades all installed packages /// Upgrades all installed packages
#[tracing::instrument(level = "trace")] #[tracing::instrument(level = "trace")]
@ -36,11 +36,11 @@ async fn upgrade_repo(options: Options) {
.await; .await;
if result.is_err() { if result.is_err() {
tracing::error!("{}", fl!("failed-upgrade-repo-pkgs")); fl_error!("failed-upgrade-repo-pkgs");
tracing::info!("{}", fl!("exiting")); fl_info!("exiting");
std::process::exit(AppExitCode::PacmanError as i32); std::process::exit(AppExitCode::PacmanError as i32);
} else { } else {
tracing::info!("{}", fl!("success-upgrade-repo-pkgs")); fl_info!("success-upgrade-repo-pkgs");
} }
} }
@ -72,7 +72,7 @@ async fn upgrade_aur(options: Options) {
aur_upgrades.push(pkg.name); aur_upgrades.push(pkg.name);
} }
} else { } else {
tracing::warn!("{}", fl!("couldnt-find-remote-pkg", pkg = pkg.name)); fl_warn!("couldnt-find-remote-pkg", pkg = pkg.name);
} }
} }
@ -83,9 +83,9 @@ async fn upgrade_aur(options: Options) {
}; };
aur_install(aur_upgrades, options).await; aur_install(aur_upgrades, options).await;
} else { } else {
tracing::info!("{}", fl!("no-upgrades-aur-package")); fl_info!("no-upgrades-aur-package");
} }
tracing::info!("{}", fl!("scanning-for-pacnew")); fl_info!("scanning-for-pacnew");
detect().await; detect().await;
} }

Loading…
Cancel
Save