From 8ee7c35b7da0cb2d1f1b1024171d8c8284212ccd Mon Sep 17 00:00:00 2001 From: Michal S Date: Mon, 17 Oct 2022 10:12:36 +0100 Subject: [PATCH] Add checkupdates subcommand for `crystal-update` compat --- i18n/en/Amethyst.ftl | 1 + src/args.rs | 3 +++ src/internal/commands.rs | 4 ++++ src/main.rs | 14 ++++++++++++++ 4 files changed, 22 insertions(+) diff --git a/i18n/en/Amethyst.ftl b/i18n/en/Amethyst.ftl index 756c618..e7baec6 100644 --- a/i18n/en/Amethyst.ftl +++ b/i18n/en/Amethyst.ftl @@ -166,6 +166,7 @@ query = Queries installed packages upgrade = Upgrades locally installed packages to their latest versions (Default) gencomp = Generates shell completions for supported shells (bash, fish, elvish, pwsh) clean = Removes all orphaned packages +checkupdates = Queries for and returns available package updates diff = Runs pacdiff install-packages = The name of the package(s) to install or search for install-aur = Operate only on AUR packages diff --git a/src/args.rs b/src/args.rs index 95b1a37..c5ccc74 100644 --- a/src/args.rs +++ b/src/args.rs @@ -60,6 +60,9 @@ pub enum Operation { #[command(bin_name = "ame", name = "clean", short_flag = 'C', about = fl!("clean"))] Clean, + #[command(bin_name = "ame", name = "checkupdates", about = fl!("checkupdates"))] + CheckUpdates, + #[command(bin_name = "ame", name = "diff", short_flag = 'd', about = fl!("diff"))] Diff, } diff --git a/src/internal/commands.rs b/src/internal/commands.rs index d9fc695..bdb6af9 100644 --- a/src/internal/commands.rs +++ b/src/internal/commands.rs @@ -69,6 +69,10 @@ impl ShellCommand { Self::new(pager) } + pub fn checkupdates() -> Self { + Self::new("checkupdates") + } + fn new(command: S) -> Self { Self { command: command.to_string(), diff --git a/src/main.rs b/src/main.rs index 446acb5..930955a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,6 +71,7 @@ async fn main() { fl_info!("removing-orphans"); operations::clean(options).await; } + Operation::CheckUpdates => cmd_checkupdates().await, Operation::GenComp(gen_args) => cmd_gencomp(&gen_args), Operation::Diff => detect().await, } @@ -231,6 +232,19 @@ async fn cmd_query(args: QueryArgs) { } } +#[tracing::instrument(level = "trace")] +async fn cmd_checkupdates() { + // TODO: Implement AUR update checking, which would then respectively display in crystal-update + println!( + "{}", + ShellCommand::checkupdates() + .wait_with_output() + .await + .silent_unwrap(AppExitCode::Other) + .stdout + ); +} + #[tracing::instrument(level = "trace")] fn cmd_gencomp(args: &GenCompArgs) { if args.shell == "fig" {