commit - 8c9adc2511caca816c705ced15a289ebcca7eeb5
commit + d4011b827873d1617a22bb1f8679545f1dca423d
blob - f8b440c832f920be1b56be73d129c3e56e1a9f7a
blob + de1b6cfabb8c4af8fc8158360af06a00dc8bad46
--- src/main.rs
+++ src/main.rs
//
// SPDX-License-Identifier: GPL-3.0-only
-use clap::{Parser, Subcommand};
+mod args;
+
+use args::Operation;
+use clap::Parser;
use raur::Raur;
-#[derive(Debug, Clone, Parser)]
-#[command(author, version, about)]
-struct Arguments {
- #[command(subcommand)]
- command: Commands,
-}
-
-#[derive(Debug, Clone, PartialEq, Subcommand)]
-enum Commands {
- /// Show packages flagged out-of-date.
- Flagged,
- /// Show packages without a maintainer.
- Orphaned,
-}
-
-trait Operation {
- fn filter(&self, p: &raur::Package) -> bool;
- fn format(&self, p: &raur::Package) -> String;
-}
-
-impl Operation for Commands {
- fn filter(&self, p: &raur::Package) -> bool {
- match self {
- Self::Flagged => p.out_of_date.is_some(),
- Self::Orphaned => p.maintainer.is_none(),
- }
- }
-
- fn format(&self, p: &raur::Package) -> String {
- match self {
- Self::Flagged => {
- if let Some(d) = p.out_of_date {
- if let Some(date) = chrono::naive::NaiveDateTime::from_timestamp_opt(d, 0) {
- let d = date.format("%Y-%m-%d").to_string();
- format!("{}: {}", p.name, d)
- } else {
- eprintln!("Invalid UNIX timestamp: {}", d);
- format!("{}: {}", p.name, d)
- }
- } else {
- p.name.to_string()
- }
- }
- Self::Orphaned => p.name.clone(),
- }
- }
-}
-
#[tokio::main]
async fn main() -> anyhow::Result<()> {
- let args = Arguments::parse();
+ let args = args::Arguments::parse();
let pacmanconf = pacmanconf::Config::new()?;
let mut alpm = alpm::Alpm::new(pacmanconf.root_dir.as_str(), pacmanconf.db_path.as_str())?;
blob - /dev/null
blob + 9eb0ac820396ee8e15bbc0c9d6b98f38571417d4 (mode 644)
--- /dev/null
+++ src/args.rs
+// SPDX-FileCopyrightText: 2023 witcher <witcher@wiredspace.de>
+//
+// SPDX-License-Identifier: GPL-3.0-only
+
+use clap::{Parser, Subcommand};
+
+pub trait Operation {
+ fn filter(&self, p: &raur::Package) -> bool;
+ fn format(&self, p: &raur::Package) -> String;
+}
+
+#[derive(Debug, Clone, Parser)]
+#[command(author, version, about)]
+pub struct Arguments {
+ #[command(subcommand)]
+ pub command: Commands,
+}
+
+#[derive(Debug, Clone, PartialEq, Subcommand)]
+pub enum Commands {
+ /// Show packages flagged out-of-date.
+ Flagged,
+ /// Show packages without a maintainer.
+ Orphaned,
+}
+
+impl Operation for Commands {
+ fn filter(&self, p: &raur::Package) -> bool {
+ match self {
+ Self::Flagged => p.out_of_date.is_some(),
+ Self::Orphaned => p.maintainer.is_none(),
+ }
+ }
+
+ fn format(&self, p: &raur::Package) -> String {
+ match self {
+ Self::Flagged => {
+ if let Some(d) = p.out_of_date {
+ if let Some(date) = chrono::naive::NaiveDateTime::from_timestamp_opt(d, 0) {
+ let d = date.format("%Y-%m-%d").to_string();
+ format!("{}: {}", p.name, d)
+ } else {
+ eprintln!("Invalid UNIX timestamp: {}", d);
+ format!("{}: {}", p.name, d)
+ }
+ } else {
+ p.name.to_string()
+ }
+ }
+ Self::Orphaned => p.name.clone(),
+ }
+ }
+}