aur_fetch/
lib.rs

1//! # aur-fetch
2//!
3//! aur-fetch is a crate that manages downloading and diffing packages downloading from the AUR.
4//! This process is split up into many different steps to give maximum control of how diffs are
5//! handled and to ensure packages are never merged until the user has confirmed they have read
6//! them.
7//!
8//! **Note:** This crate only deals with fetching packages. It assumes the list of packages you
9//! pass to it are pkgbases and therefore can not work with split packages. To deal with split
10//! packages the AUR RPC must be used to get the pkgbase from a pkgname.
11//!
12//! # Examples
13//!
14//! ## Printing - Diffs
15//!
16//! ```no_run
17//! use aur_fetch::Fetch;
18//!
19//! # use aur_fetch::Error;
20//! # async fn foo() -> Result<(), Error> {
21//!
22//! let pkgs = vec!["discord", "spotify", "pacman-git"];
23//!
24//! // Create our handle
25//! let fetch = Fetch::new()?;
26//!
27//! // Clone/Fetch the packages.
28//! let fetched = fetch.download(&pkgs)?;
29//!
30//! // Merge changes
31//! fetch.merge(&fetched)?;
32//!
33//! // Only diff packages that have not been reviewed
34//! let to_diff = fetch.unseen(&pkgs)?;
35//!
36//! // Print each diff
37//! for (diff, pkg) in fetch.diff(&to_diff, true)?.iter().zip(pkgs.iter()) {
38//!     println!("{}:", pkg);
39//!     println!("{}", diff.trim());
40//! }
41//!
42//! # Ok(())
43//! # }
44//! ```
45//!
46//! ## Diff View
47//! ```no_run
48//! use aur_fetch::Fetch;
49//! use std::process::Command;
50//!
51//! # use aur_fetch::Error;
52//! # async fn foo() -> Result<(), Error> {
53//!
54//! let pkgs = vec!["discord", "spotify", "pacman-git"];
55//!
56//! // Create our handle
57//! let fetch = Fetch::new()?;
58//!
59//! // Clone/Fetch the packages.
60//! let fetched = fetch.download(&pkgs)?;
61//!
62//! // Merge the changes.
63//! fetch.merge(&fetched)?;
64//!
65//! // Save diffs to cache.
66//! fetch.save_diffs(&fetched)?;
67//!
68//! // Make a view of the new files so we can easily see them in the file browser
69//! let dir = fetch.make_view( "/tmp/aur_view",  &pkgs, &fetched)?;
70//! Command::new("vifm").arg("/tmp/aur_view").spawn()?.wait()?;
71//!
72//! # Ok(())
73//! # }
74//! ```
75//!
76//! ## Using a Callback
77//!
78//! ```no_run
79//! use aur_fetch::Fetch;
80//!
81//! # use aur_fetch::Error;
82//! # async fn foo() -> Result<(), Error> {
83//!
84//! let pkgs = vec!["discord", "spotify", "pacman-git"];
85//!
86//! // Create our handle
87//! let fetch = Fetch::new()?;
88//!
89//! // Clone/Fetch the packages.
90//! let feteched = fetch.download(&pkgs)?;
91//!
92//! // Download the packages, printing downloads as they complete.
93//! let fetched = fetch.download_cb(&pkgs, |cb| {
94//!     println!("Downloaded ({:0pad$}/{:0pad$}): {}", cb.n, pkgs.len(), cb.pkg, pad = 3);
95//! })?;
96//!
97//! // Merge the changes.
98//! // In a real tool you would ask for user conformation before this
99//! // As long as the changes are not merged this process can always be restarted and the diffs
100//! // perserved
101//! fetch.merge(&fetched)?;
102//!
103//! # Ok(())
104//! # }
105//! ```
106#![warn(missing_docs)]
107mod callback;
108mod error;
109mod fetch;
110
111pub use callback::*;
112pub use error::*;
113pub use fetch::*;